# How to use filter using constant\_score with another query bool

**URL:** <https://discuss.elastic.co/t/how-to-use-filter-using-constant-score-with-another-query-bool/49856>\
**Category:** Elasticsearch\
**Created:** [May 12, 2016, 6:27am UTC](https://discuss.elastic.co/t/how-to-use-filter-using-constant-score-with-another-query-bool/49856 "2016-05-12T06:27:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bakhtiyor\_Homidov](https://avatars.discourse-cdn.com/v4/letter/b/51bf81/32.png) [@Bakhtiyor\_Homidov](https://discuss.elastic.co/u/Bakhtiyor_Homidov)\
**Post date:** [May 12, 2016, 6:27am UTC](https://discuss.elastic.co/t/how-to-use-filter-using-constant-score-with-another-query-bool/49856/1 "2016-05-12T06:27:24Z")

</div>

for example i've the query, and want to re-write the query using `constant_score` for filter.

```json
{
  "query": {
    "bool": {
      "must": [{ "term": { "slug": "awe2ome" } }],
      "must_not": [{ "term": { "slug": "not_awe2ome" } }],
      "should": [{ "term": { "title": "title" } }],
      "filter": [{ "term": { "is_deleted": false } }],
      "minimum_should_match": 1
    }
  }
}

```

i know the below example is wrong format.  
how to re-write the example with right format?

```json
{
  "query": {
    "bool": {
      "must": [{ "term": { "slug": "awe2ome" } }],
      "must_not": [{ "term": { "slug": "not_awe2ome" } }],
      "should": [{ "term": { "title": "title" } }],
      "minimum_should_match": 1
    },
    "constant_score": {
      "filter": {
        "bool": {
          "must": [{ "term": { "is_deleted": false } }]
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Gautam\_Vanani](https://avatars.discourse-cdn.com/v4/letter/g/a9a28c/32.png) [@Gautam\_Vanani](https://discuss.elastic.co/u/Gautam_Vanani)\
**Post date:** [March 16, 2017, 6:39pm UTC](https://discuss.elastic.co/t/how-to-use-filter-using-constant-score-with-another-query-bool/49856/2 "2017-03-16T18:39:16Z")

</div>

I'm not elastic search expert but example-1 **constant\_score** query behaves in exactly the same way as the second example. The constant\_score query assigns a score of 1.0 to all documents matched by the filter [here.](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html)

example-1

```json
{
    "query": {
     "constant_score": {
       "filter": {
         "term": {
           "status": "active"
         }}
       }
   }
}

```

* * *

example-2

```json
{
  "query": {
      "bool": {
        "filter": {
           "term": {
               "status": "active"
            }
        }
      }
  }
}

```

* * *

so You can use it like,

```json
{
  "query": {
    "bool": {
     "must": [{ "term": { "slug": "awe2ome" } }],
      "must_not": [{ "term": { "slug": "not_awe2ome" } }],
      "should": [{ "term": { "title": "title" } }],
      "minimum_should_match": 1,
      "filter": {
        "bool": {
          "must": [{ "term": { "is_deleted": false } }]
        }
      }
    }
  }
}

```

---

<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:** [July 5, 2017, 10:02pm UTC](https://discuss.elastic.co/t/how-to-use-filter-using-constant-score-with-another-query-bool/49856/3 "2017-07-05T22:02:09Z")

</div>


