How many instances of script does ElasticSearch create when it calculates a score for document?

We use custom native script that is written in Java to calculate document's score in the ElasticSearch so we want to know how many instances of script the ElasticSearch creates when it calculates a score for document? One script per document, per shard?

Thanks.

Hi @statut,

search scripts get compiled once per node and are cached afterwards. You can control the script cache with script.cache.expire (expiry in ms) and script.cache.max_size (maximum number of cached scripts).

Daniel

1 Like

Implementations of ExecutableScript and SearchScript are built fairly infrequently but not cached outside of the operations that they are performing. Like reindex will build the ExecutableScriptonce, when it first has to run the script and will reuse it forever. Script score functions build on SearchScript instance per shard.

It is instances of CompiledScript that are cached like @danielmitterdorfer says.

The lifecycle of a script isn't a thing we really guarantee though. So while I doubt we'l cache instances of SearchScript in the future because they are cheap to create you are still getting into an area that we might change as time goes on.

1 Like

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