Using scripting in aggregations
Scripting can be used in aggregations for extending its analytics capabilities both to change values used in metric aggregations or to define new rules to create buckets.
Getting ready
You need an up-and-running Elasticsearch installation as we described in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
To execute curl
via the command-line you need to install curl
for your operating system.
To correctly execute the following commands, you need an index populated with the chapter_09/populate_for_scripting.sh
script available in the sonline code and Javascript/Python Language scripting plugins installed.
How to do it...
For using a scripting language in aggregation, we will perform the following steps:
We'll write a metric aggregation that selects the field via script:
curl -XPOST 'http://127.0.0.1:9200/test-index/test- type/_search?pretty=true&size=0' -d ' { "aggs": { "my_value":...