# Elastic stores string in numeric (long) field

**URL:** <https://discuss.elastic.co/t/elastic-stores-string-in-numeric-long-field/264102>\
**Category:** Elasticsearch\
**Created:** [February 12, 2021, 9:33am UTC](https://discuss.elastic.co/t/elastic-stores-string-in-numeric-long-field/264102 "2021-02-12T09:33:58Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [February 16, 2021, 4:36pm UTC](https://discuss.elastic.co/t/elastic-stores-string-in-numeric-long-field/264102/6 "2021-02-16T16:36:17Z")

</div>

Hi just my 2 cents... got me thinking a bit

When a normal search is performed in elasticsearch it returns the source document as the `_source`, what the actual source document that was indexed .... the actual values are stored in the elsewhere (example) doc\_values so as you can see below when I do a search that returns both. In this case when you send in a "2" elasticsearch can properly convert that to a number upon indexing but it does not alter the source, that is all that is happening if it is desired to for the source to be correct ... then the correct source needs to be indexed, elasticsearch does not alter the source document, it is not a compiler like C++, if it can index it will, it has some "liberalness" to it to ease compatibility with JSON etc. and ease ingestion, I think that is perhaps considered a feature not a bug.

However when you look at the actual doc\_values you can see that in fact both are actually numeric fields.

```
DELETE my-index

PUT my-index

PUT my-index
{
  "mappings": {
    "properties": {
      "testId": {
        "type": "long"
      }
    }
  }
}

PUT my-index/_doc/1
{
  "testId": 1
}

PUT my-index/_doc/2
{
  "testId": "2"
}

PUT my-index/_doc/3
{
  "testId": "three"
}

GET my-index/_search
{
  "docvalue_fields": ["testId"], 
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "testId": {
              "gt": 0
            }
          }
        }
      ]
    }
  }
}

# Result
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 0.0,
    "hits" : [
      {
        "_index" : "my-index",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.0,
        "_source" : {
          "testId" : 1
        },
        "fields" : {
          "testId" : [
            1
          ]
        }
      },
      {
        "_index" : "my-index",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 0.0,
        "_source" : {
          "testId" : "2"
        },
        "fields" : {
          "testId" : [
            2
          ]
        }
      }
    ]
  }
}
```

---

_[View the full topic](https://discuss.elastic.co/t/elastic-stores-string-in-numeric-long-field/264102)._
