# Clearing out an index

**URL:** <https://discuss.elastic.co/t/clearing-out-an-index/13093>\
**Category:** Elasticsearch\
**Created:** [August 6, 2013, 7:14pm UTC](https://discuss.elastic.co/t/clearing-out-an-index/13093 "2013-08-06T19:14:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon\_Hilkert\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_hilkert_2/32/2182_2.png) [@Brandon\_Hilkert\_2](https://discuss.elastic.co/u/Brandon_Hilkert_2)\
**Post date:** [August 6, 2013, 7:14pm UTC](https://discuss.elastic.co/t/clearing-out-an-index/13093/1 "2013-08-06T19:14:50Z")

</div>

I'm writing a Ruby application and doing some testing with RSpec. As part  
of the RSpec setup process I'm creating indexes with the string "\_test"  
appended to the name.

After each test, I delete the indexes to ensure the data is clean for the  
next test. However, I would like to avoid doing all of if possible.

Is there a command to simply clear and existing index?

Or would I just do a match\_all query and use  
this? [http://www.elasticsearch.org/guide/reference/api/delete-by-query/](http://www.elasticsearch.org/guide/reference/api/delete-by-query/)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [August 6, 2013, 9:07pm UTC](https://discuss.elastic.co/t/clearing-out-an-index/13093/2 "2013-08-06T21:07:18Z")

</div>

I think dropping the index is the best option here. if you use delete by  
query mappings will stay around that will not work for your tests.  
What is your concern, performance?

simon

On Tuesday, August 6, 2013 9:14:50 PM UTC+2, Brandon Hilkert wrote:

> I'm writing a Ruby application and doing some testing with RSpec. As part  
> of the RSpec setup process I'm creating indexes with the string "\_test"  
> appended to the name.
> 
> After each test, I delete the indexes to ensure the data is clean for the  
> next test. However, I would like to avoid doing all of if possible.
> 
> Is there a command to simply clear and existing index?
> 
> Or would I just do a match\_all query and use this?  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/delete-by-query/)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Brandon\_Hilkert\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_hilkert_2/32/2182_2.png) [@Brandon\_Hilkert\_2](https://discuss.elastic.co/u/Brandon_Hilkert_2)\
**Post date:** [August 6, 2013, 9:45pm UTC](https://discuss.elastic.co/t/clearing-out-an-index/13093/3 "2013-08-06T21:45:34Z")

</div>

Yeah, I have to add a non-trivial amount of sleep before each test to make  
sure the test doesn't run before the index creation and fixture data gets  
pushed.

On Tue, Aug 6, 2013 at 5:07 PM, simonw [simon.willnauer@elasticsearch.com](mailto:simon.willnauer@elasticsearch.com)wrote:

> I think dropping the index is the best option here. if you use delete by  
> query mappings will stay around that will not work for your tests.  
> What is your concern, performance?
> 
> simon
> 
> On Tuesday, August 6, 2013 9:14:50 PM UTC+2, Brandon Hilkert wrote:
> 
> > I'm writing a Ruby application and doing some testing with RSpec. As part  
> > of the RSpec setup process I'm creating indexes with the string "\_test"  
> > appended to the name.
> > 
> > After each test, I delete the indexes to ensure the data is clean for the  
> > next test. However, I would like to avoid doing all of if possible.
> > 
> > Is there a command to simply clear and existing index?
> > 
> > Or would I just do a match\_all query and use this? [http://www](http://www).\*\*  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/**reference/api/delete-by-query/)[http://www.elasticsearch.org/guide/reference/api/delete-by-query/](http://www.elasticsearch.org/guide/reference/api/delete-by-query/)
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/jM8UvHrosxg/unsubscribe](https://groups.google.com/d/topic/elasticsearch/jM8UvHrosxg/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [August 6, 2013, 10:44pm UTC](https://discuss.elastic.co/t/clearing-out-an-index/13093/4 "2013-08-06T22:44:39Z")

</div>

You can use:

curl -XGET '[http://localhost:9200/\_cluster/health?wait\_for\_status=yellow&timeout=50s](http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=50s)'  
See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-cluster-health/)

HTH

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 6 août 2013 à 23:45, Brandon Hilkert [brandon@pipelinedealsco.com](mailto:brandon@pipelinedealsco.com) a écrit :

Yeah, I have to add a non-trivial amount of sleep before each test to make sure the test doesn't run before the index creation and fixture data gets pushed.

On Tue, Aug 6, 2013 at 5:07 PM, simonw [simon.willnauer@elasticsearch.com](mailto:simon.willnauer@elasticsearch.com) wrote:

> I think dropping the index is the best option here. if you use delete by query mappings will stay around that will not work for your tests.  
> What is your concern, performance?
> 
> simon
> 
> On Tuesday, August 6, 2013 9:14:50 PM UTC+2, Brandon Hilkert wrote:
> 
> > I'm writing a Ruby application and doing some testing with RSpec. As part of the RSpec setup process I'm creating indexes with the string "\_test" appended to the name.
> > 
> > After each test, I delete the indexes to ensure the data is clean for the next test. However, I would like to avoid doing all of if possible.
> > 
> > Is there a command to simply clear and existing index?
> > 
> > Or would I just do a match\_all query and use this? [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/delete-by-query/)
> 
> --  
> You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/jM8UvHrosxg/unsubscribe](https://groups.google.com/d/topic/elasticsearch/jM8UvHrosxg/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Brandon\_Hilkert\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_hilkert_2/32/2182_2.png) [@Brandon\_Hilkert\_2](https://discuss.elastic.co/u/Brandon_Hilkert_2)\
**Post date:** [August 7, 2013, 3:53pm UTC](https://discuss.elastic.co/t/clearing-out-an-index/13093/5 "2013-08-07T15:53:35Z")

</div>

Oh, this is awesome. Perfect.

On Tue, Aug 6, 2013 at 6:44 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> You can use:
> 
> curl -XGET '[http://localhost:9200/\_cluster/health?wait\_for\_status=yellow&timeout=50s](http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=50s)'
> 
> See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-cluster-health/)
> 
> HTH
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 6 août 2013 à 23:45, Brandon Hilkert [brandon@pipelinedealsco.com](mailto:brandon@pipelinedealsco.com) a  
> écrit :
> 
> Yeah, I have to add a non-trivial amount of sleep before each test to make  
> sure the test doesn't run before the index creation and fixture data gets  
> pushed.
> 
> On Tue, Aug 6, 2013 at 5:07 PM, simonw [simon.willnauer@elasticsearch.com](mailto:simon.willnauer@elasticsearch.com)wrote:
> 
> > I think dropping the index is the best option here. if you use delete by  
> > query mappings will stay around that will not work for your tests.  
> > What is your concern, performance?
> > 
> > simon
> > 
> > On Tuesday, August 6, 2013 9:14:50 PM UTC+2, Brandon Hilkert wrote:
> > 
> > > I'm writing a Ruby application and doing some testing with RSpec. As  
> > > part of the RSpec setup process I'm creating indexes with the string  
> > > "\_test" appended to the name.
> > > 
> > > After each test, I delete the indexes to ensure the data is clean for  
> > > the next test. However, I would like to avoid doing all of if possible.
> > > 
> > > Is there a command to simply clear and existing index?
> > > 
> > > Or would I just do a match\_all query and use this? [http://www](http://www).\*\*  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/guide/**reference/api/delete-by-query/)[http://www.elasticsearch.org/guide/reference/api/delete-by-query/](http://www.elasticsearch.org/guide/reference/api/delete-by-query/)
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/jM8UvHrosxg/unsubscribe](https://groups.google.com/d/topic/elasticsearch/jM8UvHrosxg/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/jM8UvHrosxg/unsubscribe](https://groups.google.com/d/topic/elasticsearch/jM8UvHrosxg/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:22am UTC](https://discuss.elastic.co/t/clearing-out-an-index/13093/6 "2017-07-06T02:22:22Z")

</div>


