Disallow Dynamic mapping in ElasticSearch

Hi,
I have a Explicit mapping defined on Elasticsearch and i want to post data in the exact format (not allowing additional properties/fields ).

eg: I have the following template defined with name biodata which gets applied to indexes starting with test*.

PUT /_template/biodata
{
"template": "test*",
"settings": {
"number_of_shards": 1
},
"mappings": {
"address" : {
"_source": {
"enabled": true
},
"properties": {
"firstname": {
"type": "string",
"index": "not_analyzed"
},
"DOB": {
"type": "date",
"format": "dd/MM/yyyy HH:mm:ss"
}
}
}
}
}

This mapping has type "address" which contains 2 properties "firstname" and "DOB". Now, i don't want Elasticsearch to accept the request which is like

POST /testindex/address/1
{
"firstname" : "SAMPLE FIRST NAME",
"DOB" : "14/09/1980 00:00:00",
"lastname" : "TEST LAST NAME",
"contact" : 123456789
}
OR

POST /testindex/address/1
{
"DOB" : "14/09/1980 00:00:00"
}

How can i achieve this? Please help

Thanks and Regards,
RK

You probably want to set the dynamic setting on the properties you don't want indexed to false. That will disallow unmapped fields from being accepted for indexing. See https://www.elastic.co/guide/en/elasticsearch/guide/current/dynamic-mapping.html

1 Like

Thanks for the reply. I was able to get good info in the specified link.
However, i have a scenario where in the above example, POST request with only "DOB" property should be rejected. I mean the POST request with subset of the specified properties should not be accepted. Elasticsearch should accept requests with only the exact properties specified in the index template.

Is there any setting to do that?

Thanks,
RK

Yes, then you want to specify dynamic as strict, see the same link for details