Skip to content

Add new Script Score Query #31461

@mayya-sharipova

Description

@mayya-sharipova

Replace Function Score Query with a new Script Score Query that will compute custom score through painless scripting.

GET /_search
{
    "query": {
        "script_score" : {
            "query": {
                "match": { "message": "elasticsearch" }
            },
            "script" : {
              "source": "Math.log(2 + doc['likes'].value)"
            },
            "min_score" : 2
        }
    }
}

Tasks:

  • Introduce a new Script Score Query
  • Develop documentation and tests for it (partially done)
  • Handle missing and multiple values in Script
    - addressed through Missing fields values unexpectedly return 0 in painless #29286 (PR submitted)
  • Introduce a new Script context in the painless
  • Add random score function to the Script context (done in Add randomScore function in script_score query #40186)
    - java's Random method should be sufficient
    - make random function that uses Lucene doc ids
    - ScriptScoreBuilder#doToQuery - investigate if we can dd salt - IndexName/ShardID to context manually
  • Add math functions to the Script context
    - rational and sigmoid functions were added
    - other functions can be implemented through Java's Math module
    - later we will be able to drop "Math" prefix in Script context
  • Add decay functions to the Script context
  • Add cosine similarity functions on dense and sparse vector fields
  • Add normalization functions to the Script context
    - will not be implemented as the implementation can be very slow, and values can be normalized through log, rational, sigmoid and other functions

relates to #27588, #30303

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions