Elasticsearch filtering by the size of a nested field that is an array


(Juan Díaz González) #1

How can I filter documents that have a nested field which is an array and has more than N elements?

For example:

"oid": "oid:user:my_user",
"updated_at": "2015-09-09T08:27:58.121216",
"versions": [
                  {  
                      properties version 1
                     },
                  { 
                     properties version 2
                  }
               ]
            }

How can I filter documents that have a field which is an empty array?

Is facets the solution? If so, how?


(Luca Cavanna) #2

Could you please clarify what type of filter you would need? also not sure what you mean when you say that the array has more than N elements. Can you clarify that too?


(Juan Díaz González) #3

yes, I would llike the filter gives me inside the type the elements (that they are composed by arrays with N elements) the elements that have more than 1 element for example.

Finally I decided by using the script filter putting my script inside the scripts dir, that it is inside config elasticsearch dir.

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-filter.html


(system) #4