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

**URL:** <https://discuss.elastic.co/t/elasticsearch-how-to-not-store-fields-that-are-not-defined-in-the-static-index/58787>\
**Category:** Elasticsearch\
**Created:** [August 24, 2016, 9:02am UTC](https://discuss.elastic.co/t/elasticsearch-how-to-not-store-fields-that-are-not-defined-in-the-static-index/58787 "2016-08-24T09:02:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stam585](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@stam585](https://discuss.elastic.co/u/stam585)\
**Post date:** [August 24, 2016, 9:02am UTC](https://discuss.elastic.co/t/elasticsearch-how-to-not-store-fields-that-are-not-defined-in-the-static-index/58787/1 "2016-08-24T09:02:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [August 24, 2016, 12:50pm UTC](https://discuss.elastic.co/t/elasticsearch-how-to-not-store-fields-that-are-not-defined-in-the-static-index/58787/2 "2016-08-24T12:50:08Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html#_reindex_to_change_the_name_of_a_field)).

Daniel

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:25pm UTC](https://discuss.elastic.co/t/elasticsearch-how-to-not-store-fields-that-are-not-defined-in-the-static-index/58787/3 "2017-07-05T22:25:32Z")

</div>


