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

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

    When you need to find documents which contains some field which size/length should be larger then zero @javanna gave correct answer. I only wanted to add if your field is text field and you want to find documents which contains some text in that field you can't use same query. You will need to do something like this:

    GET index/_search 
    {
        "query": {
            "bool": {
                "must": [
                    {
                        "range": {
                            "FIELD_NAME": {
                                "gt": 0
                            }
                        }
                    }
                ]
            }
        }
    }
    

    This is not exact answer to this question because answer already exists but solution for similar problem which I had so maybe somebody will find it useful.

提交回复
热议问题