# Filter by size of nested object

**URL:** <https://discuss.elastic.co/t/filter-by-size-of-nested-object/186410>\
**Category:** Elasticsearch\
**Created:** [June 19, 2019, 8:22am UTC](https://discuss.elastic.co/t/filter-by-size-of-nested-object/186410 "2019-06-19T08:22:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jean-Marc\_Autexier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jean-marc_autexier/32/51342_2.png) [@Jean-Marc\_Autexier](https://discuss.elastic.co/u/Jean-Marc_Autexier)\
**Post date:** [June 19, 2019, 8:22am UTC](https://discuss.elastic.co/t/filter-by-size-of-nested-object/186410/1 "2019-06-19T08:22:34Z")

</div>

Hi,

I have an index with nested objects (flags).

Example document:

> {  
> "title": "Sample title",  
> "flags": [  
> {"read"}, {"marked"}  
> ]  
> }

I want to query all documents which have more than one flag.  
How can this be done?

I tried to filter by flags.size, but get the error: No field found for [flags] in mapping with types

"query": {  
"bool": {  
"filter": {  
"script": {  
"script": "if (doc['flags'].size \> 1) {return (true)}"  
}  
}  
}  
}

---

<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:** [July 17, 2019, 8:22am UTC](https://discuss.elastic.co/t/filter-by-size-of-nested-object/186410/2 "2019-07-17T08:22:35Z")

</div>

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