Skip to content

[BUG] max_score is null when using _score as a primary sort #18714

@gaobinlong

Description

@gaobinlong

Describe the bug

When using _score as a primary sort and other field as a second sort, the max_score field in the search result is null, this is not consistent with the case of only sorting by _score:

GET logs-211998/_search
{
  "query": {
    "match": {
      "request": "english/images"
    }
  },
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    },
    {
      "@timestamp": {
        "order": "desc"
      }
    }
  ]
}

Result:
{
  "took": 2591,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 10000,
      "relation": "gte"
    },
    "max_score": null,
    "hits": [
      {
        "_index": "logs-211998",
        "_id": "OfsV8JUBd7_3mJrIyIT3",
        "_score": 0.47368687,
        "_source": {
          "@timestamp": 895968289,
          "clientip": "88.192.6.0",
          "request": "GET /english/images/team_bu_route_off.gif HTTP/1.0",
          "status": 200,
          "size": 766
        },
        "sort": [
          0.47368687,
          895968289000
        ]
      }...

But when sorting only on _score, the max_score is not null:

GET logs-211998/_search
{
  "query": {
    "match": {
      "request": "english/images"
    }
  },
  "sort": [
    {
      "_score": {
        "order": "desc"
      }
    }
  ]
}

Result:
{
  "took": 136,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 10000,
      "relation": "gte"
    },
    "max_score": 0.47368687,
    "hits": [
      {
        "_index": "logs-211998",
        "_id": "8ccV8JUBd7_3mJrIGguF",
        "_score": 0.47368687,
        "_source": {
          "@timestamp": 895552067,
          "clientip": "242.212.4.0",
          "request": "GET /english/images/news_btn_press_off.gif HTTP/1.0",
          "status": 200,
          "size": 1740
        }
      },

Related component

Search

To Reproduce

As above.

Expected behavior

max_score in the search result should not be null when using _score as a primary sort

Additional Details

OpenSearch 3.0.0 and also the main branch have the same issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    SearchSearch query, autocomplete ...etcbugSomething isn't working

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions