ElasticSearch - how to not store fields that are not defined in the static index?

I have set a static index with user entity in ES using

{
	"mappings": {
		"_default_": {
			"dynamic": "false"
		},
		"user": {
			"properties": {
				"id": {
					"type": "string"
				},
				"name": {
					"type": "string"
				},
				"age": {
					"type": "integer"
				}
			}
		}
    }
}

When I post a document with more fields than in the index it saves them to the ES.
It doesn't update the mapping but it saves the new fields.
Is there a way to remove the fields that are not in the index?

Hi @stam585,

I suggest you even set "dynamic": "strict". Then you get exceptions on insert.

You can remove unwanted fields with a script. As you also want to update the mapping, I'd just remove the fields during reindexing (see docs).

Daniel