I don't seem to understand how to prevent elasticsearch from automatically adding new mappings for new fields. The documentation states
Automatic type creation can also be disabled for all indices by setting an index template:
PUT _template/template_all
{
"template": "*",
"order":0,
"settings": {
"index.mapper.dynamic": false
}
}
So this is what I am doing:
client.admin().indices()
.preparePutTemplate("template_disable_dynamic_mapping")
.setTemplate("*")
.setSettings(Settings.builder().put("index.mapper.dynamic", false))
.get();
and after creating an index with a custom mapping for data
, I can see these mappings and setting, GET /data/_settings
returns:
{
"data": {
"mappings": {
"some_type": {
"properties": {
"value": {
"type": "text"
},
[...]
}
}
}
},
"settings": {
"index": {
"mapper": {
"dynamic": "false"
},
[...]
}
}
}
Now if I index a document with a new field foo
, it gets inserted successfully and my new mapping looks like this: GET /data/_mapping
{
"data": {
"mappings": {
"some_type": {
"properties": {
"foo": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"value": {
"type": "text"
},
[...]
}
}
}
}
}
My expectation was that no new mapping would be created.