# Field with long type is storing a double

**URL:** <https://discuss.elastic.co/t/field-with-long-type-is-storing-a-double/140557>\
**Category:** Elasticsearch\
**Created:** [July 18, 2018, 12:55pm UTC](https://discuss.elastic.co/t/field-with-long-type-is-storing-a-double/140557 "2018-07-18T12:55:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaharmor](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@shaharmor](https://discuss.elastic.co/u/shaharmor)\
**Post date:** [July 18, 2018, 12:55pm UTC](https://discuss.elastic.co/t/field-with-long-type-is-storing-a-double/140557/1 "2018-07-18T12:55:49Z")

</div>

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:

```auto
{
"_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:

```auto
{
  "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?

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [July 19, 2018, 2:17pm UTC](https://discuss.elastic.co/t/field-with-long-type-is-storing-a-double/140557/2 "2018-07-19T14:17:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 16, 2018, 2:24pm UTC](https://discuss.elastic.co/t/field-with-long-type-is-storing-a-double/140557/3 "2018-08-16T14:24:39Z")

</div>

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