Elasticsearch docs ( https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-field-mapping.html) state the following:
By default, when a previously unseen field is found in a document, Elasticsearch will add the new field to the type mapping.
So, if we create a document (for which no index/type mappings exist before hand) like this:
curl -X POST 'http://localhost:9200/my_index/food/1' -d \
'{
"name": "pie",
"delicious": true,
"age": 100.5
}'
the types are discovered automatically and the mappings for the type food
in index my_index
become:
{
"my_index": {
"mappings": {
"food": {
"properties": {
"age": { "type": "float" },
"delicious": { "type": "boolean" },
"name": {
"type": "text",
"fields": { "keyword": { "type": "keyword", "ignore_above": 256 } }
}
}
}
}
}
}
If I attempt to add a new document to index/type my_index/food for which one of the field values violates the 'contract' of the mapping specification then I find elasticsearch returns an error and declines to index the offending document.
curl -X POST 'http://localhost:9200/my_index/food/2' -d \
'{
"name": "goat",
"delicious": false,
"age": true
}'
leads to:
mapper_parsing_exception","reason":"failed to parse [age]"}],"type":"mapper_parsing_exception","reason":"failed to parse [age]","caused_by":{"type":"json_parse_exception","reason":"Current token (VALUE_TRUE) not numeric, can not use numeric value accessors\n
My question is: is there any way to configure elastic search so that my attempt to
index this document: { "name": "goat", "delicious": false, "age": true }
would just drop the (improperly typed) field 'age', and index the rest of the given document as follows:
'{ "name": "goat", "delicious": false}'
I'm guessing no search feature is available, but wanted to check. Thanks in advance!