# Clear index before update

**URL:** <https://discuss.elastic.co/t/clear-index-before-update/111837>\
**Category:** Logstash\
**Created:** [December 14, 2017, 6:20pm UTC](https://discuss.elastic.co/t/clear-index-before-update/111837 "2017-12-14T18:20:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anne.lhote](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@anne.lhote](https://discuss.elastic.co/u/anne.lhote)\
**Post date:** [December 14, 2017, 6:20pm UTC](https://discuss.elastic.co/t/clear-index-before-update/111837/1 "2017-12-14T18:20:01Z")

</div>

Hello,

I use Logstash to feed my ES from a MysQL database. Everything seems to work so far but the update. When a row is deleted on the MySQL database, the record is still present on the ES side. Is there any solution like a parameter in my Logstash conf file to clean the index before recreating it ?

Many thanks in advance !!!

Anne

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 18, 2017, 7:10pm UTC](https://discuss.elastic.co/t/clear-index-before-update/111837/2 "2017-12-18T19:10:28Z")

</div>

No, there's no such option. And even if it did, the index would be incomplete for the duration of the reindexing. What you need to do is create a new index and delete the old one. Index aliases can help here.

---

<div class="post-metadata">

**Author:** ![anne.lhote](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@anne.lhote](https://discuss.elastic.co/u/anne.lhote)\
**Post date:** [January 12, 2018, 11:06am UTC](https://discuss.elastic.co/t/clear-index-before-update/111837/3 "2018-01-12T11:06:32Z")

</div>

Thanks for your clear and fast reply !

That's what I did in my crontab :  
# Run this command every day at 01:50 AM  
# Delete the whole index of elasticsearch / INDEX  
50 1 \* \* \* root curl -X DELETE [http://localhost:9200/INDEX/](http://localhost:9200/INDEX/)  
# Run this command every day at 01:55 AM  
# Recreate an index called 'INDEX' in elasticsearch and set the mapping  
55 1 \* \* \* root curl -X PUT [http://localhost:9200/INDEX](http://localhost:9200/INDEX) -d @/path/to/my/mapping/file/mapping.json  
# Run this command every day at 02:00 AM  
# Execute the logstash command to get data from my MySQL database as put in the conf file  
0 2 \* \* \* root /path/to/my/logstash -f /path/to/my/logstash/conf/file/get-data.conf

Many thanks !

---

<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:** [February 9, 2018, 11:06am UTC](https://discuss.elastic.co/t/clear-index-before-update/111837/4 "2018-02-09T11:06:54Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
