How to generate custom score and explanation


i am looking for a way to generate new fields/scores on each search result and am lost whether this is possible at all:

Given a document and a query i want to (re)score the documents based on parameters (for example, the levenshtein distance between field1 and parameter1). It would be best to put the score in a new field in the result but overwriting the ES-score would be ok as well.
Furthermore i'd like to add an explanation to the result (again, overwriting explanations or adding a new field with an explanation).

Help is appreciated :slight_smile:

Not a direct answer, but I'll point to some building blocks that could help

You may be able to get the first part with scripted fields
you can get a script to do what you want.

One use case we focus on in the learning to rank plugin is letting you
store Elasticsearch queries and log their values in the response.

So with the plugin, you could create a feature set including a feature that
uses a fuzzy search (
and logs the score next to a document.

Modifying the explain would require a custom Lucene query plugin, and a
corresponding Elasticsearch query builder plugin. I have a blog post about
the Lucene part

Hope that helps,

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