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.