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 can i achieve it.

You can use a bool query with the dismax query as the must clause and the
filter simply as the filter section of the bool query.

Thanks Ivan, it worked :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.