I've done this in the earlier versions of elasticsearch
by simply converting the identical field (chargeamount
) within the aggs
tag which looks like this:
{
"query":{
"query_string":{
"query":"api:\"payment\" AND transactionoperationstatus:\"charged\"AND year:2016 AND month:09 AND day:01 AND userid:\"codapayments*\" AND operatorid:\"XL\" AND responsecode:(200 201)"
}
},
"aggs":{
"total":{
"terms":{
"field":"userid"
},
"aggs":{
"total":{
"sum":{
"script":{"inline" : "Double.parseDouble(doc['chargeamount'].value)"}
}
}
}
}
}
}
But then I'm struggling to do it in the elasticsearch
version 5.0.0 where initially I had to do the mapping for the index as following:
{
"mappings": {
"type": {
"properties": {
"chargeamount": {
"type": "text",
"fielddata": true
}
}
}
}
}
Then I tried to send an http POST
with the following body:
{
"query":{
"query_string":{
"query":"api:\"payment\" AND transactionoperationstatus:\"charged\"AND year:2016 AND month:09 AND day:01 AND userid:\"codapayments*\" AND operatorid:\"XL\" AND responsecode:(200 201)"
}
},
"aggs":{
"total":{
"terms":{
"field":"userid"
},
"aggs":{
"total":{
"sum":{
"script":{"inline" : "Double.parseDouble(doc['chargeamount'].value)"}
}
}
}
}
}
}
But the result still shows as a string
. Where am I going wrong?
Any help could be appreciated.