# Scripting Query for returning cases where array size is larger than X

**URL:** <https://discuss.elastic.co/t/scripting-query-for-returning-cases-where-array-size-is-larger-than-x/214892>\
**Category:** Elasticsearch\
**Created:** [January 13, 2020, 6:57pm UTC](https://discuss.elastic.co/t/scripting-query-for-returning-cases-where-array-size-is-larger-than-x/214892 "2020-01-13T18:57:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![spdoes](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@spdoes](https://discuss.elastic.co/u/spdoes)\
**Post date:** [January 13, 2020, 6:57pm UTC](https://discuss.elastic.co/t/scripting-query-for-returning-cases-where-array-size-is-larger-than-x/214892/1 "2020-01-13T18:57:25Z")

</div>

I want to make a query that counts how many elements there are in the field that is a array of jsons objects.

When I run:

{script: { script: "doc['field\_name'].values.length() \> 0"}}

I get:

"No field found for [field\_name] in mapping with types "

I have set mapping for field\_name as nested, but still I am getting the same error

I have tried multiple variations for the query but none of them worked:

"script" : "params['\_source']['field\_name'].length() \> 1"  
"script" : "params['\_source']['field\_name'].size() \> 1"  
"script" : "params['\_source']['field\_name'].values.size() \> 1"  
"script" : "params['\_source']['field\_name.keyword'].values.size() \> 1"  
"script" : {"source": "doc['ctx.\_source.field\_name'].lenght() \> 0" }}  
and other variations.

What am I doing wrong ?

---

<div class="post-metadata">

**Author:** ![spdoes](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@spdoes](https://discuss.elastic.co/u/spdoes)\
**Post date:** [January 13, 2020, 10:51pm UTC](https://discuss.elastic.co/t/scripting-query-for-returning-cases-where-array-size-is-larger-than-x/214892/2 "2020-01-13T22:51:03Z")

</div>

any more information I could provide ?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 14, 2020, 8:36am UTC](https://discuss.elastic.co/t/scripting-query-for-returning-cases-where-array-size-is-larger-than-x/214892/3 "2020-01-14T08:36:20Z")

</div>

yes, a fully reproducible example, including index creation, mapping, document indexing and the query. Also, the Elasticsearch version you are using.

Thanks!

---

<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:** [February 11, 2020, 8:36am UTC](https://discuss.elastic.co/t/scripting-query-for-returning-cases-where-array-size-is-larger-than-x/214892/4 "2020-02-11T08:36:28Z")

</div>

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