# Return documents that nested object count greather than zero

**URL:** <https://discuss.elastic.co/t/return-documents-that-nested-object-count-greather-than-zero/161660>\
**Category:** Elasticsearch\
**Created:** [December 20, 2018, 10:41am UTC](https://discuss.elastic.co/t/return-documents-that-nested-object-count-greather-than-zero/161660 "2018-12-20T10:41:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![irajchardoli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/irajchardoli/32/49798_2.png) [@irajchardoli](https://discuss.elastic.co/u/irajchardoli)\
**Post date:** [December 20, 2018, 10:41am UTC](https://discuss.elastic.co/t/return-documents-that-nested-object-count-greather-than-zero/161660/1 "2018-12-20T10:41:08Z")

</div>

Hi ,  
Please let me know ,how to return documents that nested object count is greater than zero.  
i want first filter nested object then return documents that have nested object number greather than zero.

```auto
products:[
{ id=1 ,number="01" ,name="iphone" ,prices:[{Enabled = true ,price = 1} ,{Enabled = false,price = 2}] } ,

{ id=2 ,number="02" ,name="samsung" ,prices:[{Enabled = false ,price = 10} ,{Enabled = false,price = 20}] },
]

```

for "products" document must be return products that have at least one "Enabled" prices.  
result must be:  
{ id=1 ,number="01" ,name="iphone" ,prices:[{Enabled = true ,price = 1}] }

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 20, 2018, 11:18am UTC](https://discuss.elastic.co/t/return-documents-that-nested-object-count-greather-than-zero/161660/2 "2018-12-20T11:18:40Z")

</div>

Use a nested query with a term query in it which checks for enabled = true.

(I consider that you indexed individual products which is unclear here)

---

<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:** [January 17, 2019, 11:18am UTC](https://discuss.elastic.co/t/return-documents-that-nested-object-count-greather-than-zero/161660/3 "2019-01-17T11:18:44Z")

</div>

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