# Delete index from elasticsearch thru spark scala code

**URL:** <https://discuss.elastic.co/t/delete-index-from-elasticsearch-thru-spark-scala-code/90464>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [June 22, 2017, 1:33pm UTC](https://discuss.elastic.co/t/delete-index-from-elasticsearch-thru-spark-scala-code/90464 "2017-06-22T13:33:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jobyjohny](https://avatars.discourse-cdn.com/v4/letter/j/eada6e/32.png) [@jobyjohny](https://discuss.elastic.co/u/jobyjohny)\
**Post date:** [June 22, 2017, 1:33pm UTC](https://discuss.elastic.co/t/delete-index-from-elasticsearch-thru-spark-scala-code/90464/1 "2017-06-22T13:33:59Z")

</div>

I am creating a spark object which contains the stats of a table and writing into elasticsearch  
val cases\_count\_stats = spark.sql("select col2,count(\*) from table group by col2"  
cases\_count\_stats.saveToEs("abc/def")

How do I delete the index everything before I create it ?

---

<div class="post-metadata">

**Author:** ![james.baiera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/james.baiera/32/10209_2.png) [@james.baiera](https://discuss.elastic.co/u/james.baiera)\
**Post date:** [June 22, 2017, 7:10pm UTC](https://discuss.elastic.co/t/delete-index-from-elasticsearch-thru-spark-scala-code/90464/2 "2017-06-22T19:10:45Z")

</div>

Elasticsearch for Apache Spark supports the [OVERWRITE save mode](https://spark.apache.org/docs/latest/sql-programming-guide.html#save-modes) from Spark's data source api. Could use that.

---

<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 20, 2017, 7:10pm UTC](https://discuss.elastic.co/t/delete-index-from-elasticsearch-thru-spark-scala-code/90464/3 "2017-07-20T19:10:55Z")

</div>

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