If the numbers after the decimal is zero, it doesn't return as a double value?


(Kulasangar Gowrisangar) #1

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).

Where am I going wrong? Any help could be appreciated.


(Christoph) #2

Hi,

What do you mean by "doesn't return a double value"? Can you show us a Put and Get/Search operation with a document that shows the unexpected behaviour? If you mean that if you

PUT /index/type/1
{ "chargeamount" : "1.56" }

your get

"hits": [
      {
        "_index": "index",
        "_type": "type",
        "_id": "1",
        "_score": 1,
        "_source": {
          "chargeamount": "1.56"
        }
      }, [...]

That is to be expected, because Elasticsearch returns the original document exactly as it was entered in the "_source" field.
Other than that, with the above mapping your values should be index as doubles.


(Kulasangar Gowrisangar) #3

I'm sending a POST request as such in order to retrieve data from the index:

http://myhostmachine:9402/myindex/_search?

And this is what I have in my body:

{  
	"size" : 10,
	"_source": ["chargeamount"], 
   "query":{  
      "query_string":{  
         "query":"myquery"
      }
   },
   "aggs":{  
      "total":{  
         "terms":{  
            "field":"user"
         },
         "aggs":{  
            "total":{
               "sum":{  
                   "field": "chargeamount" 
               }
            }
         }
      }
   }
}

And the result looks like this:

http://pastebin.com/he39pU2B

At the bottom of the results, you could see the aggs total doesn't return a double value.


(system) #4