# Cutoff\_frequency yields different results using filtered filter query or filtered query

**URL:** <https://discuss.elastic.co/t/cutoff-frequency-yields-different-results-using-filtered-filter-query-or-filtered-query/26482>\
**Category:** Elasticsearch\
**Created:** [July 29, 2015, 12:47pm UTC](https://discuss.elastic.co/t/cutoff-frequency-yields-different-results-using-filtered-filter-query-or-filtered-query/26482 "2015-07-29T12:47:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjtuner](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sjtuner](https://discuss.elastic.co/u/sjtuner)\
**Post date:** [July 29, 2015, 12:47pm UTC](https://discuss.elastic.co/t/cutoff-frequency-yields-different-results-using-filtered-filter-query-or-filtered-query/26482/1 "2015-07-29T12:47:45Z")

</div>

Hello everybody

I encountered a behavior I haven't expected with my current understanding how elastic search works. Obviously I did not understand as much as I thought 🙂

Both queries shown below look only slightly different and finally boil down to a match query. However, they return a different amount of document, i.e., the first returns more then the second.

First query:

```
{
  "size": 0,
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": {
            "query": {
              "match": {
                "mydata.freetext": {
                  "query": "Elastic"
}}}}}}}}}

```

Second:

```
{
  "size": 0,
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "must": {
            "match": {
              "mydata.freetext": {
                "query": "Elastic"
}}}}}}}}

```

Can anyone explain me why they return different results?

Thanks in advance!

Stefan

---

<div class="post-metadata">

**Author:** ![msimos](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@msimos](https://discuss.elastic.co/u/msimos)\
**Post date:** [July 29, 2015, 5:42pm UTC](https://discuss.elastic.co/t/cutoff-frequency-yields-different-results-using-filtered-filter-query-or-filtered-query/26482/2 "2015-07-29T17:42:58Z")

</div>

I'm not really sure why the results are different but when using a filter, without specifying a query it uses match\_all query. Where as the second one is a query with no filter. You can also use ?explain to see whats happening in \_explanation.

[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html)

---

<div class="post-metadata">

**Author:** ![msimos](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@msimos](https://discuss.elastic.co/u/msimos)\
**Post date:** [July 29, 2015, 5:50pm UTC](https://discuss.elastic.co/t/cutoff-frequency-yields-different-results-using-filtered-filter-query-or-filtered-query/26482/3 "2015-07-29T17:50:48Z")

</div>

Also this may help you understand the differences between a query vs a filter and why the results are different.

[https://www.elastic.co/guide/en/elasticsearch/guide/current/\_queries\_and\_filters.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/_queries_and_filters.html)

---

<div class="post-metadata">

**Author:** ![sjtuner](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sjtuner](https://discuss.elastic.co/u/sjtuner)\
**Post date:** [July 29, 2015, 6:30pm UTC](https://discuss.elastic.co/t/cutoff-frequency-yields-different-results-using-filtered-filter-query-or-filtered-query/26482/4 "2015-07-29T18:30:14Z")

</div>

Hello Mike,

thanks for your suggestions. The Explain API did not tell me a lot of understandable stuff. For that to be useful one would probably have to have deep insight in the mechanics of lucene.

I just encountered that I reduced my actual queries too much for showing here and I therewith missed the (how I encountered) problematic part. Next try, see below, I removed the bool-parts and instead kept in the cutoff\_frequency which is responsible for the different countings. If I remove the cutoff\_frequency, both queries return the same results. Leaving the property in leads to different results. However, my question remains the same:

First query v2:

```
{
  "size": 0,
  "query": {
    "filtered": {
      "filter": {
            "query": {
              "match": {
                "mydata.freetext": {
                "query": "Elastic",
                "cutoff_frequency": 0.001
}}}}}}}

```

Second query v2:

```
{
  "size": 0,
  "query": {
    "filtered": {
      "query": {
        "match": {
          "mydata.freetext": {
            "query": "Elastic",
            "cutoff_frequency": 0.001
}}}}}}

```

Any ideas why this is the case?

Best regards, Stefan

---

<div class="post-metadata">

**Author:** ![msimos](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@msimos](https://discuss.elastic.co/u/msimos)\
**Post date:** [July 29, 2015, 7:58pm UTC](https://discuss.elastic.co/t/cutoff-frequency-yields-different-results-using-filtered-filter-query-or-filtered-query/26482/5 "2015-07-29T19:58:05Z")

</div>

There isn't any scoring for filters, so I don't believe cutoff\_frequency would do anything. See the following:

[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html)

"they don’t have to calculate the relevance \_score for each document — the answer is just a boolean “Yes, the document matches the filter” or “No, the document does not match the filter”."

---

<div class="post-metadata">

**Author:** ![sjtuner](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sjtuner](https://discuss.elastic.co/u/sjtuner)\
**Post date:** [July 29, 2015, 8:03pm UTC](https://discuss.elastic.co/t/cutoff-frequency-yields-different-results-using-filtered-filter-query-or-filtered-query/26482/6 "2015-07-29T20:03:30Z")

</div>

cutoff\_frequency isn't about scoring in the first place, as far as I know. It's about the frequency of terms appearing in documents, right?

Furthermore, since the cutoff\_frequency is embedded in a query, the calculation should take place here anyway, right? Only when the wrapping filter comes into play, the calculated scores are omitted...at least this is what I think how it works. This thesis is supported by the fact, that removing the cutoff-frequency increases the number of documents being found again.

Further ideas? I really don't get it. Played around a bit and I don't get the mechanism here.

---

<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:58pm UTC](https://discuss.elastic.co/t/cutoff-frequency-yields-different-results-using-filtered-filter-query-or-filtered-query/26482/7 "2017-07-05T23:58:16Z")

</div>


