1

The official elasticsearch guide says: https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html

Store and retrieve scripts You can store and retrieve scripts from the cluster state using the stored script APIs. Stored scripts reduce compilation time and make searches faster.

How do stored scripts reduce compilation time and make searches faster compared to inline scripts?

1 Answer 1

2

Stored scripts are compiled once at the time they are stored in the cluster state, whereas inline scripts are compiled on each query invocation.

From there, it's trivial to deduce that stored scripts are faster than inline ones.

UPDATE January 2025:

Indeed, compilation time is not reduced in stored scripts. Furthermore, since all scripts (stored and inlined) are pre-compiled, the only reason stored scripts could be "faster" lies in the fact that stored scripts are stored in the cluster state and don't need to be sent on every request. Depending on the size of your scripts and the frequency at which you're sending them, stored scripts might be better for lowering the request payload and latency.

PR 119921 will amend the official documentation to better reflect the above.

Sign up to request clarification or add additional context in comments.

3 Comments

hmm are you sure? because according to an answer in Elastic Forum: "A stored script isn't faster. We cache the compilation of inline scripts as well as stored scripts. We don't precompile stored scripts because we don't know what they'll be used for." (discuss.elastic.co/t/…) Now I got two opposite answers for this question and not sure whatever answer is more accurate
@AmjedOmar thanks for raising this. As both answers (Nik's an mine) are pretty old, let me dig a bit to figure out what's the current state in the latest versions. I'll provide some feedback
@AmjedOmar Indeed, stored scripts aren't faster, they are pre-compiled and cached the same way as inlined scripts. We'll amend the documentation to better reflect this (see PR 119921) and I've also updated my answer above

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.