Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch: how to use dismax query with filter

I am having hard time to figure out how to use elsticsearch dis_max query with filters.

When I do this:

{
    "query": {
        "dis_max": {
            "queries": [{
                "multi_match": {}
            },
            { 
                "multi_match": {}
            }],
            "filter": {
                //Term filter
            }           
        }
    }
}

Its says [dis_max] query does not support [filter]. but I can use dis_max query with filtered aliases.

Ex: I create an alias with filter defined like below and use the same while doing dis_max query and it works perfectly.

 {
   "add" : {
       "index" : "test1",
       "alias" : "alias1",
       "filter" : { //Term filter }
    }
 }

So there should be someway to achieve this without creating aliases. can anyone please tell me how to do it.

like image 721
ManuAc Avatar asked May 04 '17 15:05

ManuAc


Video Answer


1 Answers

If anyone is looking for an answer, I ended up using the bool query with my dis_max query in must class and filter simply as the filter section of the bool query.

Ex:

{
    "query": {
        "bool": {
            "must": {
                "dis_max": {
                    "queries": [{
                         "multi_match": {}
                     },
                     { 
                         "multi_match": {}
                     }]
                }
            }
            "filter": {
                //Term filter
            }           
        }
    }
}
like image 125
ManuAc Avatar answered Oct 07 '22 21:10

ManuAc