Im generating a custom field using "script_fields". And I would like to use that field to generate score for the documents. How can I achieve this in elasticsearch. It would be great if any one could post an example query.
1 Answer
It's not really possible because when scores for the document are calculated the script field values are not computed yet. Search requests are typically executed in two phases: query and fetch. During the query phase scores are calculated and top documents are selected for retrieval. The list of the top documents is then used during fetch phase to retrieve the documents. During this retrieval process the script fields are calculated.
In other words in order to use script to score the documents, you need to use this script in the query phase by placing it into the function_score query, for example