Computing return fields with scripting
ElasticSearch allows you to define complex expressions that can be used to return a new calculated field value. These special fields are called script_fields, and they can be expressed with a script in every available ElasticSearch scripting language.
Getting ready
You will need a working ElasticSearch cluster and an index populated with the script (chapter_06/populate_aggregations.sh) used in Chapter 6, Aggregations, which is available at https://github.com/aparo/elasticsearch-cookbook-second-edition.
How to do it...
In order to compute return fields with scripting, perform the following steps:
- Return the following script fields:
"my_calc_field": This concatenates the text of the"name"and"description"fields"my_calc_field2": This multiplies the"price"value by the"discount"parameter
- From the command line, execute the following code:
curl -XGET 'http://127.0.0.1:9200/test-index/test-type...