Min_score doesnt apply to aggregates

Hi there,

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

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:

{
  "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:

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?

{
  "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!

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