I'm having an index created in elasticsearch 5.0
, where it contains data from my MySQL
db. There's a field which is a string
in my table, which I need it as a double
in ES.
So what I did was added the mapping when I created the index for the appropriate field using a PUT
:
{
"mappings": {
"my_type": {
"properties": {
"chargeamount": {
"type": "double"
}
}
}
}
}
After I did this, a value which contains numbers after the decimal (ie: 23.23) returns the value properly as a double but where as numbers which has zeros after the decimal (ie: 23.00) returns it as a string itself (ie: 2300).
EDIT: These are the steps which I did:
I initially created the index through a
PUT
request (http://hostmachine:9402/indexname
) with the above mapping as the body.Then I'm pushing the data (from my MySQL table) to the index using
logstash
. I could provide the logstash conf if needed.Once the data is being uploaded to the index, I tried querying as such in order to check whether the result shows a double value. The
POST
request (http://hostmachine:9402/indexname/_search?
and the body as follows :{ "size" : 0, "query":{ "query_string":{ "query":"myquery" } }, "aggs":{ "total":{ "terms":{ "field":"userid" }, "aggs":{ "total":{ "sum":{ "script":{ "lang": "painless", "inline" : "doc['chargeamount'].value" } } } } } } }
And the result looks like as in the snapshot below, where it should've been 267472.00:
Where am I going wrong? Any help could be appreciated.