# Indexing string as integer then getting back the integer value in search result

**URL:** <https://discuss.elastic.co/t/indexing-string-as-integer-then-getting-back-the-integer-value-in-search-result/98721>\
**Category:** Elasticsearch\
**Created:** [August 29, 2017, 3:17pm UTC](https://discuss.elastic.co/t/indexing-string-as-integer-then-getting-back-the-integer-value-in-search-result/98721 "2017-08-29T15:17:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikeThomsen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikethomsen/32/19378_2.png) [@MikeThomsen](https://discuss.elastic.co/u/MikeThomsen)\
**Post date:** [August 29, 2017, 3:17pm UTC](https://discuss.elastic.co/t/indexing-string-as-integer-then-getting-back-the-integer-value-in-search-result/98721/1 "2017-08-29T15:17:18Z")

</div>

A team I am working with has a lot of dirty data. Sometimes a field might be a string, sometimes an integer for a particular field in several related Mongo collections. When it's a string, we can always rely on it being a valid integer, so these two work just fine:

```
PUT index/1
{
    "field": 1
}

PUT index/2
{
    "field": "2"
}

```

However, the \_source field in the latter returns "field" as a string. Cleaning up the source data is not an option for me because it's outside of my authority. So is there a way to have ElasticSearch return "field" consistently as an integer or am I always going to be stuck with getting it back as whatever form it was indexed (integer or string)?

---

<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:** [September 26, 2017, 3:17pm UTC](https://discuss.elastic.co/t/indexing-string-as-integer-then-getting-back-the-integer-value-in-search-result/98721/2 "2017-09-26T15:17:18Z")

</div>

Closed on September 26, 2017, 3:17pm UTC

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