# What is the difference between a filter clause in a query or a filter

**URL:** <https://discuss.elastic.co/t/what-is-the-difference-between-a-filter-clause-in-a-query-or-a-filter/44232>\
**Category:** Elasticsearch\
**Created:** [March 12, 2016, 4:49pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-a-filter-clause-in-a-query-or-a-filter/44232 "2016-03-12T16:49:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![WilliamRoma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/williamroma/32/8322_2.png) [@WilliamRoma](https://discuss.elastic.co/u/WilliamRoma)\
**Post date:** [March 12, 2016, 4:49pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-a-filter-clause-in-a-query-or-a-filter/44232/1 "2016-03-12T16:49:13Z")

</div>

I have these two queries

**First**

```
GET propertywebsites3/_search
{
  "_source": "city", 
  "query": {
    "bool": {
      "filter": {
        "term": {
          "city.raw": "Dubai"
        }
      }
    }
  }
}

```

**Seond**

```
GET propertywebsites3/_search
{
  "_source": "city", 
  "query": {
    "filtered": {
      "filter": {
        "term": {
          "city.raw": "Dubai"
        }
      }
    }
  }
}

```

The first one gives 0 for all the scores, I see that in this page [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html) it is written that if you use the filter clause in a bool clause, all matching documents will have 0 in the score,

and the second query gives 1 to the score of all the documents.

first of all why not both of them either 0 or 1. second aren't they supposed to do they same? which is filtering all the documents that its city is "Dubai" ?

thanks

---

<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:** [March 12, 2016, 5:55pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-a-filter-clause-in-a-query-or-a-filter/44232/2 "2016-03-12T17:55:09Z")

</div>

Filtered query has been deprecated. See [https://www.elastic.co/guide/en/elasticsearch/reference/2.2/query-dsl-filtered-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.2/query-dsl-filtered-query.html)

---

<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:** [March 12, 2016, 5:56pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-a-filter-clause-in-a-query-or-a-filter/44232/3 "2016-03-12T17:56:24Z")

</div>

If you add a match\_all query in the must clause of the bool query, what is the score?

---

<div class="post-metadata">

**Author:** ![WilliamRoma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/williamroma/32/8322_2.png) [@WilliamRoma](https://discuss.elastic.co/u/WilliamRoma)\
**Post date:** [March 12, 2016, 6:17pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-a-filter-clause-in-a-query-or-a-filter/44232/4 "2016-03-12T18:17:59Z")

</div>

Thanks for your reply.

If I add a match\_all, the score becomes all 1 instead of 0.

So if I understood you correctly, whenever i want to do a filter now, I should use a bool clause with a filter clause inside , right please?

---

<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:** [March 18, 2016, 11:09am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-a-filter-clause-in-a-query-or-a-filter/44232/5 "2016-03-18T11:09:11Z")

</div>

right!

So the reason with the difference between the score is that the `filtered` query actually adds a `match_all` query which set the `_score` to 1 for each document and the `bool` query does not add a query.

---

<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, 11:07pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-a-filter-clause-in-a-query-or-a-filter/44232/6 "2017-07-05T23:07:13Z")

</div>


