# Insert float data into Integer type success

**URL:** <https://discuss.elastic.co/t/insert-float-data-into-integer-type-success/360691>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [June 3, 2024, 6:45am UTC](https://discuss.elastic.co/t/insert-float-data-into-integer-type-success/360691 "2024-06-03T06:45:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lht](https://avatars.discourse-cdn.com/v4/letter/l/ee7513/32.png) [@lht](https://discuss.elastic.co/u/lht)\
**Post date:** [June 3, 2024, 6:45am UTC](https://discuss.elastic.co/t/insert-float-data-into-integer-type-success/360691/1 "2024-06-03T06:45:08Z")

</div>

I attempted to create a field of type integer in Elasticsearch, expecting to only be able to insert integers. However, I found that I was able to insert integers, floating-point numbers, and even strings (using co.elastic.clients:elasticsearch-java:8.13.2).

Here are the Kibana requests and Java code that I used, and I'm wondering why this is happening.

Kibana requests:

```auto
PUT /my_index1  
{  
  "mappings": {  
    "properties": {  
      "integer_test": {  
        "type": "integer"  
      }
    }  
  }  
}
put /my_index1/_doc/1 
{  
  "integer_test": 8.88 
}
POST /my_index1/_doc/2
{  
  "integer_test": "2.22" 
}

```

java api code：

```auto
HashMap map = new HashMap();
map.put("integertest", "aaa");

int finalI = 4;
IndexRequest request = IndexRequest.of(
		idx -> idx.index("my_index1")
				.id(String.valueOf(finalI))
				.document(JsonData.of(map)));
client.index(request);

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 3, 2024, 7:08am UTC](https://discuss.elastic.co/t/insert-float-data-into-integer-type-success/360691/2 "2024-06-03T07:08:50Z")

</div>

Welcome

If you don't want Elasticsearch to try its best by accepting the data, you can try this option: [coerce | Elasticsearch Guide [8.13] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/coerce.html)

It should reject your document I think.

---

<div class="post-metadata">

**Author:** ![lht](https://avatars.discourse-cdn.com/v4/letter/l/ee7513/32.png) [@lht](https://discuss.elastic.co/u/lht)\
**Post date:** [June 3, 2024, 8:57am UTC](https://discuss.elastic.co/t/insert-float-data-into-integer-type-success/360691/3 "2024-06-03T08:57:33Z")

</div>

it works，tks
