# How to use dismax query with filter

**URL:** <https://discuss.elastic.co/t/how-to-use-dismax-query-with-filter/84656>\
**Category:** Elasticsearch\
**Created:** [May 5, 2017, 5:39am UTC](https://discuss.elastic.co/t/how-to-use-dismax-query-with-filter/84656 "2017-05-05T05:39:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ManuAc](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@ManuAc](https://discuss.elastic.co/u/ManuAc)\
**Post date:** [May 5, 2017, 5:39am UTC](https://discuss.elastic.co/t/how-to-use-dismax-query-with-filter/84656/1 "2017-05-05T05:39:54Z")

</div>

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.
```

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [May 5, 2017, 6:04am UTC](https://discuss.elastic.co/t/how-to-use-dismax-query-with-filter/84656/2 "2017-05-05T06:04:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ManuAc](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@ManuAc](https://discuss.elastic.co/u/ManuAc)\
**Post date:** [May 5, 2017, 6:43pm UTC](https://discuss.elastic.co/t/how-to-use-dismax-query-with-filter/84656/3 "2017-05-05T18:43:03Z")

</div>

Thanks Ivan, it worked 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 2, 2017, 6:46pm UTC](https://discuss.elastic.co/t/how-to-use-dismax-query-with-filter/84656/4 "2017-06-02T18:46:50Z")

</div>

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