Using scripts
ElasticSearch has a few functionalities where scripts can be used. You've already seen examples such as updating documents, filtering, and searching. Regardless of the fact that this seems to be advanced, we will take a look at the possibilities given by ElasticSearch. Looking into any request that use scripts, we can spot several fields:
script
: This field contains the script code.lang
: This field informs the engine which language is used. If it is omitted, ElasticSearch assumesmvel
.params
: This is an object containing parameters. Every defined parameter is available for script by its name. By using parameters, we can write cleaner code. Due to caching, code with parameters performs better than code with embedded constant values.
Available objects
During the execution of the script, ElasticSearch exposes several objects. The ones available for operations connected with searching are as follows:
doc
(also available as_doc
): This is an instance of theorg.elasticsearch.search...