Type to search.

Incorporating static relevance signals into the score

Serverless

Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Serverless interfaces and procedures might differ from classic Elastic Stack deployments.

Stack

The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

Many domains have static signals that are known to be correlated with relevance. For instance PageRank and url length are two commonly used features for web search in order to tune the score of web pages independently of the query.

There are two main queries that allow combining static score contributions with textual relevance, eg. as computed with BM25:

For instance imagine that you have a pagerank field that you wish to combine with the BM25 score so that the final score is equal to score = bm25_score + pagerank / (10 + pagerank).

With the script_score query the query would look like this:

JSON
GET index/_search
{
  "query": {
    "script_score": {
      "query": {
        "match": { "body": "elasticsearch" }
      },
      "script": {
        "source": "_score * saturation(doc['pagerank'].value, 10)"
      }
    }
  }
}
  1. pagerank must be mapped as a Numeric

while with the rank_feature query it would look like below:

JSON
GET _search
{
  "query": {
    "bool": {
      "must": {
        "match": { "body": "elasticsearch" }
      },
      "should": {
        "rank_feature": {
          "field": "pagerank",
          "saturation": {
            "pivot": 10
          }
        }
      }
    }
  }
}
  1. pagerank must be mapped as a rank_feature field

While both options would return similar scores, there are trade-offs: script_score provides a lot of flexibility, enabling you to combine the text relevance score with static signals as you prefer. On the other hand, the rank_feature query only exposes a couple ways to incorporate static signals into the score. However, it relies on the rank_feature and rank_features fields, which index values in a special way that allows the rank_feature query to skip over non-competitive documents and get the top matches of a query faster.