Closed
Description
Recently, I was using ElasticsearchRestTemplate and found that it seems that the parameters of the script cannot be carried when defining runtime fields in a search request. What should I do to carry the parameters?
Like this script:
double price = 0;
for (int i = 0; i < params._source.pool_quotas.length; ++i) {
if (params._source.pool_quotas[i].pool_id==params.pool_id){
price += params._source.pool_quotas[i].hard_limit;
}
}
emit(price);
it looks:
{
"from": 0,
"size": 10,
"query": {
"bool": {
"should": [{
"term": {
"name": {
"value": "wangfei",
"boost": 1.0
}
}
}],
"adjust_pure_negative": true,
"minimum_should_match": "1",
"boost": 1.0
}
},
"version": true,
"explain": false,
"runtime_mappings": {
"duration": {
"type": "double",
"script": {
"source": "double price = 0;for (int i = 0; i < params._source.pool_quotas.length; ++i) {if (params._source.pool_quotas[i].pool_id==params.pool_id){price += params._source.pool_quotas[i].hard_limit;}}emit(price);",
"lang": "painless",
"params": {
"pool_id": "cddaca80-6480-45af-85c2-b09577db4396"
}
}
}
}
}
How can I implement a query like this?Thanks!