# Elasticsearch scoring and filter context

**URL:** <https://discuss.elastic.co/t/elasticsearch-scoring-and-filter-context/235397>\
**Category:** Elasticsearch\
**Created:** [June 2, 2020, 7:00pm UTC](https://discuss.elastic.co/t/elasticsearch-scoring-and-filter-context/235397 "2020-06-02T19:00:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Faiz\_Ahmed\_Mushtak\_H](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/faiz_ahmed_mushtak_h/32/47387_2.png) [@Faiz\_Ahmed\_Mushtak\_H](https://discuss.elastic.co/u/Faiz_Ahmed_Mushtak_H)\
**Post date:** [June 2, 2020, 7:00pm UTC](https://discuss.elastic.co/t/elasticsearch-scoring-and-filter-context/235397/1 "2020-06-02T19:00:47Z")

</div>

We are working on building a internal query language that converts to ES7 query. I'd like to know what are the implications of generating the following kinds of queries in ES

```auto
#1.1

{
  "query": {
    "bool": {
      "must": [
        ...
      ],
      "filter": [
        ...
      ]
    }
  }
}

#1.2
{
  "query": {
    "bool": {
      "filter": {
        "must": [
        ...
        ],
        "filter": [
          ...
        ]
      }
    }
  }
}

```

Is ES smart enough to not score the must clause in 1.2 because it is in filter context?

EDIT:

I ran a few experiment with 1.1 and 1.2 and 1.2 was a tad bit slower! I actually expected 1.1 to be slower because of scoring!

We do see a lot of cache miss count. We are using the default cache settings. misses are around 400k whereas hits are around 30-40k

Surprisingly

```auto
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "customer(keyword_field)": "big_customer"
          }
        }
      ]
    }
  }
}

```

is faster than (10 times .. 140ms vs 11ms)

```auto
{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "customer(keyword_field)": "big_customer"
          }
        }
      ]
    }
  }
}

```

^^ for this, when i added sorting, they both slowed down and were roughly performing the same

---

<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 30, 2020, 7:01pm UTC](https://discuss.elastic.co/t/elasticsearch-scoring-and-filter-context/235397/2 "2020-06-30T19:01:00Z")

</div>

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