ES Script reusing the values


We have script field stored in file. We need script field to display and also for sorting.
Looks like script is executed two times, one for showing the field in the response and another time for sorting.

Is there any way, we can avoid this execution two times?
i.e run the script one time, use this result for display and sort.


The script is executed two times because it is used within two different contexts within the search. Instead of specifying a sort script, you can use a script score. The score is always returned, so you can use it for display, and it is also the default sort.

@rjernst thanks for the reply..
We are also planning to use that approach..

Only problem is, We have multiple script fields,
Depending on request, we may have sort on one or more script fields
So, checking if there is way to cache the results of script and use it in other place

There is no way to cache results of scripts. These are executed in completely different ares of the codebase.

Thank you @rjernst

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