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:
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:
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);