# Min\_score doesnt apply to aggregates

**URL:** <https://discuss.elastic.co/t/min-score-doesnt-apply-to-aggregates/315503>\
**Category:** Elasticsearch\
**Created:** [September 29, 2022, 9:37pm UTC](https://discuss.elastic.co/t/min-score-doesnt-apply-to-aggregates/315503 "2022-09-29T21:37:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![reisner](https://avatars.discourse-cdn.com/v4/letter/r/e9bcb4/32.png) [@reisner](https://discuss.elastic.co/u/reisner)\
**Post date:** [September 29, 2022, 9:37pm UTC](https://discuss.elastic.co/t/min-score-doesnt-apply-to-aggregates/315503/1 "2022-09-29T21:37:06Z")

</div>

Hi there,

I'm seeing some weird behaviour trying to fix an issue with a query. I was originally running this query:

```auto
GET /coe_td_council_report_files_test/_search
{
  "size": 0,
  "min_score": 2.9,
  "query": {
      "bool": {
          "must": {
              "simple_query_string": {
                  "query": "budget",
                  "fields": ["text"]
              }
          }
      }
  },
  "aggs": {
    "group_by_index": {
        "terms": {
            "field": "_index"
        }
    }
  }
}

```

and I got these results. Note that `doc_count` doesnt match total hits below, and from what I've read online, thisis because `min_score` doesnt apply to aggregations:

```auto
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 702,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  },
  "aggregations" : {
    "group_by_index" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "coe_td_council_report_files_test",
          "doc_count" : 14021
        }
      ]
    }
  }
}

```

For some reason, the following fixes the issue, and I'm not sure why:

```auto
GET /coe_td_council_report_files_test/_search
{
  "size": 0,
  "min_score": 2.9,
  "query": {
      "bool": {
          "must": {
              "simple_query_string": {
                  "query": "budget",
                  "fields": ["text"]
              }
          }
      }
  },
  "aggs": {
    "group_by_index": {
      "range": {
          "script": {
            "source": "_score"
          },
          "ranges": [
              {
                  "from": 0
              }
            ]
      },
      "aggs": {
        "colors": {
          "terms": {
            "field": "_index"
          }
        }
      }
    }
  }
}

```

Here are the results for the above. Why does the doc\_count now match the total hits? Ive only added a ranges query for score \> 0. It also works when I set the `from` to be 2.9, and this is what I would expect, but why does it still work when the from is `0`?

```auto
{
  "took" : 9,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 702,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  },
  "aggregations" : {
    "group_by_index" : {
      "buckets" : [
        {
          "key" : "0.0-*",
          "from" : 0.0,
          "doc_count" : 702,
          "colors" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 0,
            "buckets" : [
              {
                "key" : "coe_td_council_report_files_test",
                "doc_count" : 702
              }
            ]
          }
        }
      ]
    }
  }
}

```

I'm on Elastic v 8.1.3 if that helps.

Also, if there's a better way to do this than to specify the score in two spots, that would also be helpful!

Thank you!

---

<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:** [October 27, 2022, 9:37pm UTC](https://discuss.elastic.co/t/min-score-doesnt-apply-to-aggregates/315503/2 "2022-10-27T21:37:07Z")

</div>

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