sree
sree

Reputation: 902

elastic search returning no results filtering on multi value field

I have a field in the elastic search called category and it contains multiple values. Below are the sample values

"category": [
                    "Commercial",
                    "CafeBarRestaurant",
                    "Tables"
                ],

Now I am querying the elasticsearch to get the document where the category is "Commercial". Below is my query:

{
 "from":0,
 "size":40,
 "query":{
  "bool":{
     "filter":[
        {
           "bool":{
              "must":[
                 {
                    "term":{
                       "category":{
                          "value":"Commercial",
                          "boost":1.0
                       }
                    }
                 }
              ],
              "adjust_pure_negative":true,
              "boost":1.0
           }
        }
     ],
     "adjust_pure_negative":true,
     "boost":1.0
  }

} } Mapping:

{
"products": {
    "mappings": {
        "category": {
            "full_name": "category",
            "mapping": {
                "category": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                }
            }
        }
    }
}

}

Every time it is giving me empty results. Can anyone suggest to me what wrong in the query. Thanks.

Upvotes: 0

Views: 348

Answers (1)

Lupanoide
Lupanoide

Reputation: 3212

You don't need bool. try:

{
  "query: {
      "match": {
          "category": "Commercial"}}  }

or:

{
  "query: {
      "term": {
          "category.keyword": "Commercial"}}  }

Upvotes: 1

Related Questions