# \[7.5.0\] Field mapped as a long appears as a string

**URL:** <https://discuss.elastic.co/t/7-5-0-field-mapped-as-a-long-appears-as-a-string/212453>\
**Category:** Elasticsearch\
**Created:** [December 19, 2019, 9:05am UTC](https://discuss.elastic.co/t/7-5-0-field-mapped-as-a-long-appears-as-a-string/212453 "2019-12-19T09:05:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)\
**Post date:** [December 19, 2019, 9:05am UTC](https://discuss.elastic.co/t/7-5-0-field-mapped-as-a-long-appears-as-a-string/212453/1 "2019-12-19T09:05:44Z")

</div>

Hi there!

I'm experiencing a strange issue. I've got an index with a template where a given mapping is specified. Such a mapping includes a specific field which should be a `long`.

It works perfectly for almost all the documents in the index, but for some of them, even if the field acts as a long (I can do metric like avg and max over it), it does look like a string in the JSON.

Apparently it is causing some problems when another team queries ES via API, since the returned value is a string.

Here it is how the field appears (correctly) in most of the documents

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/c/ac759c5f823ec90d69108874dd240d22aa154b44.png)  
Here it is how it appears in some documents  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/3/4/34466cfce6f43490f2739bc75310a5f948120d98.png)

I even tried running a reindex on the original index, specifying again the mapping of that field, but result is the same.

Does anybody have any ideas about why it acts like that?

Thanks

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 19, 2019, 10:15am UTC](https://discuss.elastic.co/t/7-5-0-field-mapped-as-a-long-appears-as-a-string/212453/2 "2019-12-19T10:15:25Z")

</div>

The feature you may want to read about is called [coerce](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/coerce.html) and can be disabled.

Hope this helps!

--Alex

---

<div class="post-metadata">

**Author:** ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)\
**Post date:** [December 20, 2019, 11:17am UTC](https://discuss.elastic.co/t/7-5-0-field-mapped-as-a-long-appears-as-a-string/212453/3 "2019-12-20T11:17:36Z")

</div>

Mhmh interesting... shouldn't it be `true` by default anyway? 🤔

However, thank you so much for your prompt and useful reply.  
For anybody interested in fixing the same issue without reindexing with the `coerce` set to true, here's the ingest pipeline I used to update the index:

```
{
  "string_to_long_pipeline" : {
    "description" : "Convert a specific field from String to Long where needed",
    "processors" : [
      {
        "script" : {
          "source" : """
            if (ctx.containsKey('specific_field') && ctx.specific_field instanceof String) {
              def to_long = Long.parseLong(ctx.specific_field);
              ctx.specific_field = to_long
            }
          """
        }
      }
    ]
  }
}
```

---

<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:** [January 17, 2020, 11:17am UTC](https://discuss.elastic.co/t/7-5-0-field-mapped-as-a-long-appears-as-a-string/212453/4 "2020-01-17T11:17:38Z")

</div>

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