Computing return fields with scripting
Elasticsearch allows us to define custom complex expressions that can be used to return a newly calculated field value.
The most common scenarios for these use cases are as follows:
- Merge field values (that is, first name + last name)
- Compute values (that is, total=quantity*price)
- Apply transformations (that is, convert dollars to euros, string manipulation)
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 an up-and-running Elasticsearch installation, similar to the one that we described in the Downloading and installing Elasticsearch recipe in Chapter 1, Getting Started.
To execute the commands, any HTTP client can be used, such as cURL (https://curl.haxx.se/) or Postman (https://www.getpostman.com/). You can use Kibana Console, as it provides code completion and better character escaping for...