Skip to content

[Feature Request] Introduce a rescore search response processor #15631

@mingshl

Description

@mingshl

Is your feature request related to a problem? Please describe

When a field with score is added by a response processor, we try to sort the response by the added field.

in the search response, there are multiple documents in hits. a rescore search response processor can take the score from a field from the document, and sort the search hits based on the field value. Users can opt to remove the field in the documents.

Describe the solution you'd like

The proposed solution as follows:

PUT /_search/pipeline/my_pipeline
{
  "response_processors": [
    {
      "rescore": {
        "field": "similarity_score",
        "sort": "desc",
        "replace_score": true 
        "remove_sort_field" : true
      }
    }
  ]
}

for example:

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 4,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "diary_index",
        "_id": "1",
        "_score": 1,
        "_source": {
          "diary": "how are you",
          "similarity_score": -11.055182
        }
      },
      {
        "_index": "diary_index",
        "_id": "2",
        "_score": 1,
        "_source": {
          "diary": "today is sunny",
          "similarity_score": 8.969885
        }
      },
      {
        "_index": "diary_index",
        "_id": "3",
        "_score": 1,
        "_source": {
          "diary": "today is july fifth",
          "similarity_score": -5.736348
        }
      },
      {
        "_index": "diary_index",
        "_id": "4",
        "_score": 1,
        "_source": {
          "diary": "it is winter",
          "similarity_score": -10.045217
        }
      }
    ]
  }
}

the response after processing:

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 4,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [

{
        "_index": "diary_index",
        "_id": "2",
        "_score": 8.969885,
        "_source": {
          "diary": "today is sunny"
        }
      },
      {
        "_index": "diary_index",
        "_id": "3",
        "_score": -5.736348,
        "_source": {
          "diary": "today is july fifth"
        }
      },
      {
        "_index": "diary_index",
        "_id": "4",
        "_score": -10.045217,
        "_source": {
          "diary": "it is winter"
        }
      }
      , {
        "_index": "diary_index",
        "_id": "1",
        "_score": -11.055182,
        "_source": {
          "diary": "how are you"
        }
      }
    ]
  }
}

Related component

Search

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

SearchSearch query, autocomplete ...etcenhancementEnhancement or improvement to existing feature or requestv2.18.0Issues and PRs related to version 2.18.0

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions