Type to search.

Search using LTR

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.

Note

This feature was introduced in version 8.12.0 and is only available to certain subscription levels. For more information, refer to Elastic self-managed subscriptions.

Once your LTR model is trained and deployed in Elasticsearch, there are two ways to use it with the search API to improve your search results:

  1. As a rescorer
  2. As a retriever

To use your LTR model as a rescorer in the search API, follow this example:

JSON
GET my-index/_search
{
  "query": {
    "multi_match": {
      "fields": ["title", "content"],
      "query": "the quick brown fox"
    }
  },
  "rescore": {
    "learning_to_rank": {
      "model_id": "ltr-model",
      "params": {
        "query_text": "the quick brown fox"
      }
    },
    "window_size": 100
  }
}
  1. First pass query providing documents to be rescored.
  2. The unique identifier of the trained model uploaded to Elasticsearch.
  3. Named parameters to be passed to the query templates used for feature.
  4. The number of documents that should be examined by the rescorer on each shard.

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 9.1+

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

Availability

  • Generally available since 9.1

    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.

LTR models can also be used as a retriever in the search pipeline. You can implement this with a rescorer retriever as shown in the following example:

JSON
GET my-index/_search
{
  "retriever": {
    "rescorer": {
      "rescore": {
        "window_size": 100,
        "learning_to_rank": {
          "model_id": "ltr-model",
          "params": {
            "query_text": "the quick brown fox"
          }
        }
      },
      "retrievers": [
        {
          "standard": {
            "query": {
              "multi_match": {
                "fields": ["title", "content"],
                "query": "the quick brown fox"
              }
            }
          }
        }
      ]
    }
  }
}
  1. First pass retrievers used to retrieve documents to be rescored
  2. The unique identifier of the trained model uploaded to Elasticsearch.
  3. Named parameters to be passed to the query templates used for feature extraction.
  4. The number of documents that should be examined by the rescorer.

Scores returned by LTR models are usually not comparable with the scores issued by the first pass query and can be lower than the non-rescored score. This can cause the non-rescored result document to be ranked higher than the rescored document. To prevent this, the window_size parameter is mandatory for LTR rescorers and should be greater than or equal to from + size.

When exposing pagination to users, window_size should remain constant as each page is progressed by passing different from values. Changing the window_size can alter the top hits causing results to confusingly shift as the user steps through pages.