# Replace filered query with bool/must query

**URL:** <https://discuss.elastic.co/t/replace-filered-query-with-bool-must-query/95293>\
**Category:** Elasticsearch\
**Created:** [August 1, 2017, 7:38am UTC](https://discuss.elastic.co/t/replace-filered-query-with-bool-must-query/95293 "2017-08-01T07:38:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karolinebryn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karolinebryn/32/17095_2.png) [@Karolinebryn](https://discuss.elastic.co/u/Karolinebryn)\
**Post date:** [August 1, 2017, 7:38am UTC](https://discuss.elastic.co/t/replace-filered-query-with-bool-must-query/95293/1 "2017-08-01T07:38:47Z")

</div>

Hi!  
This is my existing query (used with ES 1.7).

```
{
   "query":{
      "filtered":{
         "query":{
            "function_score":{
               "functions":[
                  ...
               ],
               "query":{
                  "bool":{
                     "should":[
                        ...
                     ]
                  }
               },
               "filter":{
                  ...
               }
            }
         }
      }
   }
}

```

I have now upgraded to ES 5.4, and this query no longer works due to the fact that filtered queries are removed from ES 5. I understand that you should use a bool/must query instead, but I cannot figure out how to rewrite my query to fit this change. Any suggestions?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 2, 2017, 7:40am UTC](https://discuss.elastic.co/t/replace-filered-query-with-bool-must-query/95293/2 "2017-08-02T07:40:44Z")

</div>

You should be able to write something like:

```auto
{
  "query": {
    "bool": {
      "must": [
        {
          "function_score": {
            "functions": [...],
            "query": {
              "bool": {
                "should": [...]
              }
            }
          }
        }
      ],
      "filter": {
        ... 
      }
    }
  }
}

```

---

<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:** [August 30, 2017, 7:40am UTC](https://discuss.elastic.co/t/replace-filered-query-with-bool-must-query/95293/3 "2017-08-30T07:40:51Z")

</div>

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