Filter nested objects from a document

Hi all,

I'm starting with ES, I'm doing some tests and right now I have a doubt, I explain it:

in my example each document are a shoes and each one has a nested object (items) which contains the color, the sizes and a price.

....
"items": [
{
"color": "white",
"sizes": [
"37"
],
"price": "60",
"old_price": ""
},
{
"color": "blue",
"sizes": [
"40",
"42",
"45"
],
"price": "65",
"old_price": ""
},
...
]
...

I want to filter the documents and at the same time filter the nested field "items", I attached you an image I think is more clear than words.

I've tried with several filters options but nothing, Is that possible? or should I change the data structure?

Thank you very much.

Regards
Santi

I think I've finally found the way (in fact was Bo Andersen who did it, if you are here, thanks!!), with the option inner_hits we can get the hitted nested objects. It can be used also into post_filter:

Into post_filter:

"post_filter": {
    "nested": {
      "path": "items",
      "query": {
        "bool": {
          "must": [
            { "term": { "items.sizes.keyword": { "value": "40" } } },
            { "term": { "items.sizes.keyword": { "value": "39" } } }
          ]
        }
      },
      "inner_hits": {
       
       }
      }   
  }

Thanks you all
Santi

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.