I have the following document
{
"id": 1,
"store": "xyz",
"products": [
{
"object": {
"name": "chair",
"code": "2584"
},
"parts": [
{
"material": "wood"
},
{
"material": "steel"
}
]
}
]
},
{
"id": 2,
"store": "abc",
"products": [
{
"object": {
"name": "chair",
"code": "2584"
},
"parts": [
{
"material": "wood"
},
{
"material": "steel"
}
]
},
{
"object": {
"name": "table",
"code": "2678"
},
"parts": [
{
"material": "wood"
},
{
"material": "steel"
}
]
}
]
}
So it goes like this : List of stores -> list of products -> list of parts
Now I would like to make a query to get all stores that have a chair in the products lists, but I don't want to have all the products in the response
For example the store "abc" should return for the query:
{
"id": 2,
"store": "abc",
"products": [
{
"object": {
"name": "chair",
"code": "2584"
},
"parts": [
{
"material": "wood"
},
{
"material": "steel"
}
]
}
}
Currently my mapping is :
"products.object": {
"type": "object",
"properties": {
"code": {
"type": "text",
"fielddata": true
},
"name": {
"type": "text",
"fielddata": true
}
}
},
"products.parts": {
"store": false,
"type": "long",
"index": false
},
What type of query should I use and how the mapping should be made ?
Thank you in advance
EDIT :
To add to my question, my goal is to remove all products that dont match the query inside the hits array
So the response should contain the id, the variable "store", and so on. But not the products that dont match the name "chair" (to echo my example)