ElasticSearch allows us 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.
You need a working ElasticSearch cluster and an index populated with the script used for facet processing, available in the online code.
For computing return fields with scripting, we will perform the following steps:
Return the following script fields:
"my_calc_field"
: This concatenates the texts of the"name"
and"description"
fields"my_calc_field2"
: This multiplies the"price"
value by the"discount"
parameter
From the command-line, we will execute the following code:
curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_search?&pretty=true&size=3' -d '{ "query": { "match_all": {} }, "script_fields" : { "my_calc_field" : { "script" : "doc[\"name\"...