# Filter nested objects from a document

**URL:** <https://discuss.elastic.co/t/filter-nested-objects-from-a-document/96327>\
**Category:** Elasticsearch\
**Created:** [August 8, 2017, 6:59pm UTC](https://discuss.elastic.co/t/filter-nested-objects-from-a-document/96327 "2017-08-08T18:59:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![santrod](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@santrod](https://discuss.elastic.co/u/santrod)\
**Post date:** [August 8, 2017, 6:59pm UTC](https://discuss.elastic.co/t/filter-nested-objects-from-a-document/96327/1 "2017-08-08T18:59:34Z")

</div>

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.

 ![Console Kibana](https://us1.discourse-cdn.com/elastic/original/3X/b/7/b76104c97cadaacec04d1a7dec011c2c02ddda9e.png)

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

---

<div class="post-metadata">

**Author:** ![santrod](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@santrod](https://discuss.elastic.co/u/santrod)\
**Post date:** [August 9, 2017, 8:55am UTC](https://discuss.elastic.co/t/filter-nested-objects-from-a-document/96327/2 "2017-08-09T08:55:30Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html#nested-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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 6, 2017, 8:55am UTC](https://discuss.elastic.co/t/filter-nested-objects-from-a-document/96327/3 "2017-09-06T08:55:31Z")

</div>

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