elasticsearch filtering by the size of a field that is an array

后端 未结 8 963
旧巷少年郎
旧巷少年郎 2020-12-08 03:47

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

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

8条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 04:36

    Based on this: https://code.google.com/p/guava-libraries/source/browse/guava/src/com/google/common/collect/RegularImmutableList.java?r=707f3a276d4ea8e9d53621d137febb00cd2128da

    And on lisak's answer here.

    There is size() function which returns the length of list:

    "filter" : {
        "script" : {
            "script" : "doc['fieldname'].values.size() > 10"
        }
    }
    

提交回复
热议问题