This is not realistic, because when evaluating the document, the values of the script field are not yet calculated. Search queries are usually performed in two stages: query and fetch . During the query, phase estimates are computed and the top documents are selected for retrieval. The list of top documents is then used during selection to retrieve documents. During this search process, script fields are computed.
In other words, to use a script to evaluate documents, you need to use this script in the request phase by placing it in function_score , e.g.
source
share