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

后端 未结 8 958
旧巷少年郎
旧巷少年郎 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:27

    If you have an array of objects that aren't mapped as nested, keep in mind that Elastic will flatten them into:

    attachments: [{size: 123}, {size: 456}] --> attachments.size: [123, 456]
    

    So you want to reference your field as doc['attachments.size'].length, not doc['attachments'].length, which is very counter-intuitive.

    Same for doc.containsKey(attachments.size).

    The .values part is deprecated and no longer needed.

提交回复
热议问题