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

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 ?

any more information I could provide ?

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

Thanks!

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