# Losing mappings when I delete documents?

**URL:** <https://discuss.elastic.co/t/losing-mappings-when-i-delete-documents/37389>\
**Category:** Elasticsearch\
**Created:** [December 16, 2015, 6:20pm UTC](https://discuss.elastic.co/t/losing-mappings-when-i-delete-documents/37389 "2015-12-16T18:20:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mc1392](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@mc1392](https://discuss.elastic.co/u/mc1392)\
**Post date:** [December 16, 2015, 6:20pm UTC](https://discuss.elastic.co/t/losing-mappings-when-i-delete-documents/37389/1 "2015-12-16T18:20:42Z")

</div>

I like to refresh my index daily with a cron job using the following to delete documents in a given index:

`curl -XDELETE 'http://localhost:9200/'$1'/?pretty=true'`  
Where $1 is the index name passed in.

Problem is I seem to lose my mappings on the index.  
For example, I have a field I want as `'NOT_ANALYZED'`. This works on the initial load when I create the index and the mapping at once. But once I run the above delete command, my mappings are not there.

Is this the proper way to delete documents from my index? If not , how do I do so using curl command?

---

<div class="post-metadata">

**Author:** ![msimos](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@msimos](https://discuss.elastic.co/u/msimos)\
**Post date:** [December 16, 2015, 8:01pm UTC](https://discuss.elastic.co/t/losing-mappings-when-i-delete-documents/37389/2 "2015-12-16T20:01:31Z")

</div>

Using:

```auto
curl -XDELETE 'http://localhost:9200/'$1'/?pretty=true'

```

Will delete the entire index including all documents and the mapping. So this is expected. So you have a few choices:

1. Save your mapping and as part of your cron job recreate the index with the mapping:

[https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html)

```auto
curl -XPUT http://localhost:9200/myindex -d @mapping.json

```

1. Create an index template, so that when you recreate your index it automatically gets applied:

[https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html)

1. If you're using Elasticsearch 2.x, you can use the delete by query plugin to delete all the documents and not remove the entire index:

[https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugins-delete-by-query.html](https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugins-delete-by-query.html)

---

<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, 11:30pm UTC](https://discuss.elastic.co/t/losing-mappings-when-i-delete-documents/37389/3 "2017-07-05T23:30:26Z")

</div>


