# Java to delete all the documents in the Elastic search using json queries

**URL:** <https://discuss.elastic.co/t/java-to-delete-all-the-documents-in-the-elastic-search-using-json-queries/199625>\
**Category:** Elasticsearch\
**Created:** [September 16, 2019, 9:46am UTC](https://discuss.elastic.co/t/java-to-delete-all-the-documents-in-the-elastic-search-using-json-queries/199625 "2019-09-16T09:46:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Velliyangiri](https://avatars.discourse-cdn.com/v4/letter/v/50afbb/32.png) [@Velliyangiri](https://discuss.elastic.co/u/Velliyangiri)\
**Post date:** [September 16, 2019, 9:46am UTC](https://discuss.elastic.co/t/java-to-delete-all-the-documents-in-the-elastic-search-using-json-queries/199625/1 "2019-09-16T09:46:35Z")

</div>

Give me the code snippet for elastic search 7.3.0 to delete all the records in the index using match all json query in a java code.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 16, 2019, 10:32am UTC](https://discuss.elastic.co/t/java-to-delete-all-the-documents-in-the-elastic-search-using-json-queries/199625/2 "2019-09-16T10:32:45Z")

</div>

Just use [the delete index API](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-delete-index.html) if you want to remove everything.

---

<div class="post-metadata">

**Author:** ![Velliyangiri](https://avatars.discourse-cdn.com/v4/letter/v/50afbb/32.png) [@Velliyangiri](https://discuss.elastic.co/u/Velliyangiri)\
**Post date:** [September 17, 2019, 5:28am UTC](https://discuss.elastic.co/t/java-to-delete-all-the-documents-in-the-elastic-search-using-json-queries/199625/3 "2019-09-17T05:28:05Z")

</div>

That should be completely deleting the index.. I need to deleting the full documents inside the index.Help me

---

<div class="post-metadata">

**Author:** ![Velliyangiri](https://avatars.discourse-cdn.com/v4/letter/v/50afbb/32.png) [@Velliyangiri](https://discuss.elastic.co/u/Velliyangiri)\
**Post date:** [September 17, 2019, 5:35am UTC](https://discuss.elastic.co/t/java-to-delete-all-the-documents-in-the-elastic-search-using-json-queries/199625/4 "2019-09-17T05:35:19Z")

</div>

Iam not need for deleting the index. Iam only need for delete all the records inside the index .  
Please help me

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [September 17, 2019, 5:41am UTC](https://discuss.elastic.co/t/java-to-delete-all-the-documents-in-the-elastic-search-using-json-queries/199625/5 "2019-09-17T05:41:29Z")

</div>

You can do this using [delete by query](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/docs-delete-by-query.html), which results in all documents being deleted individually. This can be quite slow and expensive and simply deleting and recreating the index is much more fast and efficient.

---

<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:** [October 15, 2019, 5:46am UTC](https://discuss.elastic.co/t/java-to-delete-all-the-documents-in-the-elastic-search-using-json-queries/199625/6 "2019-10-15T05:46:12Z")

</div>

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