Script Based Sorting & query-based score

Hi. Is it possible to combine painless script-based sorting with default query-based score? What I'm after is this:

{
  "query": {
    "simple_query_string": {
      "fields": ["name"],
      "query": "foobar*"
    }
  },
  "sort": {
    "_script": {
      "type": "number",
      "script": "doc.someValue.value * 1.1 - ${SCORE_OF_THE_QUERY}",
      "order": "desc"
    }
  }
}

If not possible, any tips on how to handle this? Basically I need the similarity of the name to have certain importance but also take into account the numerical document values (someValue in this example).

Thanks!

You should look at a function score query with a script_score. The original score of a document will be available to the script as _score.

1 Like

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