# Why Elastic Search allow to put number in text field?

**URL:** <https://discuss.elastic.co/t/why-elastic-search-allow-to-put-number-in-text-field/341756>\
**Category:** Elasticsearch\
**Created:** [August 27, 2023, 10:34am UTC](https://discuss.elastic.co/t/why-elastic-search-allow-to-put-number-in-text-field/341756 "2023-08-27T10:34:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krzysztof\_Lempicki](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krzysztof_lempicki/32/124502_2.png) [@Krzysztof\_Lempicki](https://discuss.elastic.co/u/Krzysztof_Lempicki)\
**Post date:** [August 27, 2023, 10:34am UTC](https://discuss.elastic.co/t/why-elastic-search-allow-to-put-number-in-text-field/341756/1 "2023-08-27T10:34:48Z")

</div>

Hi,

I have mapping like this:

```auto
     "mappings": {
                            "dynamic": "strict",
                            "properties": {
                              "name": {
                                "type": "text"
                              }
                            }}

```

when I add new document:

```auto
POST /my_index/_bulk
{ "index":{} }
{"name":123}

```

everything is fine and result of search is:

```auto
   "hits": [
      {
        "_index": "my_index",
        "_id": "gUuDNooBpc7sew2t4t-R",
        "_score": 1,
        "_source": {
          "name": 123
        }
      },
      {
        "_index": "my_index",
        "_id": "gkuGNooBpc7sew2tud_d",
        "_score": 1,
        "_source": {
          "name": 123
        }
      },
      {
        "_index": "my_index",
        "_id": "g0uHNooBpc7sew2tL9_4",
        "_score": 1,
        "_source": {
          "name": 123
        }
      }

```

## Question

How to make ES to not accept incorrect type data?  
So if field is text, numbers should be rejected

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [August 27, 2023, 3:04pm UTC](https://discuss.elastic.co/t/why-elastic-search-allow-to-put-number-in-text-field/341756/2 "2023-08-27T15:04:54Z")

</div>

> [@Krzysztof\_Lempicki](#):
>
> How to make ES to not accept incorrect type data?  
> So if field is text, numbers should be rejected

I don't think you can because the data type is not incorrect for elasticsearch.

Mapping a field as `text` or `keyword` for example doesn't mean that it will only accept text characters, it means that the value of the field will be treated as a string even if it is a number.

In your example, the value `123` is not a numeric value for elasticsearch, you can't do numeric operations with the field `name`.

So you can't make elasticsearch reject numeric values for text/keyword fields, if this is something that youe use case needs, then you will need to validate it before sending the data to Elasticsearch.

---

<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 24, 2023, 3:05pm UTC](https://discuss.elastic.co/t/why-elastic-search-allow-to-put-number-in-text-field/341756/3 "2023-09-24T15:05:30Z")

</div>

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