Ivan
Ivan

Reputation: 525

Elasticsearch: multi_match no effect with filters

I try to be brief. This search does not apply the search keywords present in multi_match. Any search text I insert, I always get the same result.

If I delete filtered / filter, it gives me a proper search. Why?

GET /catalog/products/_search
{
   "from":0,
   "size":150,
   "query":{
      "filtered":{
         "query":{
            "multi_match":{
               "query":"text to search",
               "fields":[
                  "title^5",
                  "description"
               ]
            },
            "filter":{
               "and":[
                  {
                     "term":{
                        "category": 2
                     }
                  },
                  {
                     "not":{
                        "term":{
                           "subCategory": 3
                        }
                     }
                  }
               ]
            }
         }
      }
   }
}

Upvotes: 0

Views: 105

Answers (1)

skal88
skal88

Reputation: 484

Put the filter on the same level at query, like this:

GET /catalog/products/_search
{
    "from":0,
    "size":150,
    "query":{
      "filtered":{
        "query":{
          "multi_match":{
             "query":"text to search",
             "fields":[
                "title^5",
                "description"
             ]
          }
        },
        "filter":{
           "and":[
              {
                 "term":{
                    "category": 2
                 }
              },
              {
                 "not":{
                    "term":{
                       "subCategory": 3
                    }
                 }
              }
           ]
        }
      }
    }
} 

Upvotes: 2

Related Questions