Field with long type is storing a double


(Shahar Mor) #1

Hi,

ES 6.2.4

I'm not sure how this happened, but I have a document that is stored in an index where one of the fields is with a mapping of long, but the document is storing a double value in it.

This is the doc:

{
"_source": {
    "id": "c998cdbd9a2240c2adeefe72fa91e33e",
    "metrics": {
      "played": 59990.999755859375
    }
  }
}

It obviously has more fields, but the metrics.played one is the important one.

This is the mapping of that index:

{
  "index-name": {
    "mappings": {
      "doc": {
        "dynamic": "strict",
        "properties": {
          "metrics": {
            "properties": {
              "played": {
                "type": "long"
              }
            }
          }
        }
      },
      "_default_": {
        "dynamic": "strict",
        "properties": {
          "metrics": {
            "properties": {
              "played": {
                "type": "long"
              }
            }
          }
        }
      }
    }
  }
}

Is this because of the coerce option? it rounds up the value?


(Abdon Pijpelink) #2

That is exactly what's happening - the coerce feature casts this value to a long value (I believe it will get rounded down).

So, even though the _source (which always is your original document) shows you a floating point number, Elasticsearch will actually treat this value as a long when querying or aggregating it.


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.