Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Term Filter in array only consider the last item?

I want to search document in elastic search which has either tag a or b or c with the following query. But it always return the document which has only c and ignore a or b. Any one can help it out?

"filtered": {
            "filter": {
                "term": {
                    "tags": ['a','b','c']
                }
            },
            "query": {
                match: {
                    rawText: 'filter'
                }

            }
        }
like image 351
Md. Rashim Uddin Avatar asked Aug 02 '15 08:08

Md. Rashim Uddin


1 Answers

In Elasticsearch, there is a difference between the term and the terms filter.

Term Filter:

{
    "constant_score" : {
        "filter" : {
            "term" : { "user" : "kimchy"}
        }
    }
}

Terms Filter:

{
    "constant_score" : {
        "filter" : {
            "terms" : {
                "user" : ["kimchy", "elasticsearch"],
                "execution" : "bool",
                "_cache": true
            }
        }
    }
}

Try using the terms filter.

like image 59
MauricioRoman Avatar answered Sep 28 '22 03:09

MauricioRoman