I would like to dynamically calculate some values and retrieve the calculated values along with the original fields instead of only calculated. Say, there are fields "userId", "value". Additionally, I would like to calculate "additionalParameter". In order to do that, the following simple script has been added:
"query": {
"match": {
"userId": "1161851"
}
},
"script_fields": {
"additionalParameter": {
"script": {
"lang": "painless",
"source": "doc['value'] * factor",
"params": {
"factor": 2.0
}
}
}
}
When the above query is executed, however, I get only additionalParameter:
{
"_index" : "test_index",
"_type" : "doc",
"_id" : "dd57ba66-a31a-45f1-9948-18ff4fb27dc1",
"_score" : 3.0488422,
"fields" : {
"additionalParameter" : [
10.0
]
}
},
...
Does anyone know what is the right way to append calculated values to original fields and retrieve all?