# How-to delete objects in index by query?

**URL:** <https://discuss.elastic.co/t/how-to-delete-objects-in-index-by-query/6735>\
**Category:** Elasticsearch\
**Created:** [February 17, 2012, 4:36am UTC](https://discuss.elastic.co/t/how-to-delete-objects-in-index-by-query/6735 "2012-02-17T04:36:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yuriy\_Vasilyev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuriy_vasilyev/32/2854_2.png) [@Yuriy\_Vasilyev](https://discuss.elastic.co/u/Yuriy_Vasilyev)\
**Post date:** [February 17, 2012, 4:36am UTC](https://discuss.elastic.co/t/how-to-delete-objects-in-index-by-query/6735/1 "2012-02-17T04:36:57Z")

</div>

Hi to all!

When I'm sending request for delete objects by query, ElasticSearch  
removes all records in index, not only one with id 1404.0.0 (I have  
string id)  
My request here

DELETE [http://10.54.xx.xx:9200/test\_create/address\_search/?pretty=true](http://10.54.xx.xx:9200/test_create/address_search/?pretty=true)  
HTTP/1.1  
Accept: application/json  
Content-Type: application/json  
Host: 10.54.18.47:9200  
Content-Length: 64  
Expect: 100-continue  
Connection: Keep-Alive

{ "query" : {  
"terms" : { "id" : ["1404.0.0"] }  
} }

Thanks,  
Yuriy

---

<div class="post-metadata">

**Author:** ![David\_Stendardi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_stendardi/32/2990_2.png) [@David\_Stendardi](https://discuss.elastic.co/u/David_Stendardi)\
**Post date:** [February 17, 2012, 6:33am UTC](https://discuss.elastic.co/t/how-to-delete-objects-in-index-by-query/6735/2 "2012-02-17T06:33:55Z")

</div>

I think you are using the wrong endpoint : You are deleting the whole  
type "address\_search"

You should replace :  
[http://10.54.xx.xx:9200/test\_create/address\_search/?pretty=true](http://10.54.xx.xx:9200/test_create/address_search/?pretty=true)  
by : [http://10.54.xx.xx:9200/test\_create/address\_search/\_query?pretty=true](http://10.54.xx.xx:9200/test_create/address_search/_query?pretty=true)

as stated here :

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

2012/2/17 Yuriy Vasilyev [rus.xprogrammer@gmail.com](mailto:rus.xprogrammer@gmail.com):

> Hi to all!
> 
> When I'm sending request for delete objects by query, Elasticsearch  
> removes all records in index, not only one with id 1404.0.0 (I have  
> string id)  
> My request here
> 
> DELETE [http://10.54.xx.xx:9200/test\_create/address\_search/?pretty=true](http://10.54.xx.xx:9200/test_create/address_search/?pretty=true)  
> HTTP/1.1  
> Accept: application/json  
> Content-Type: application/json  
> Host: 10.54.18.47:9200  
> Content-Length: 64  
> Expect: 100-continue  
> Connection: Keep-Alive
> 
> { "query" : {  
> "terms" : { "id" : ["1404.0.0"] }  
> } }
> 
> Thanks,  
> Yuriy

--  
David Stendardi

---

<div class="post-metadata">

**Author:** ![Yuriy\_Vasilyev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yuriy_vasilyev/32/2854_2.png) [@Yuriy\_Vasilyev](https://discuss.elastic.co/u/Yuriy_Vasilyev)\
**Post date:** [February 17, 2012, 7:37am UTC](https://discuss.elastic.co/t/how-to-delete-objects-in-index-by-query/6735/3 "2012-02-17T07:37:22Z")

</div>

I added \_query and fixed my query as

{  
"terms" : { "id" : ["1404.0.0"] }  
}

All works fine!

Thank you!

---

<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, 3:38am UTC](https://discuss.elastic.co/t/how-to-delete-objects-in-index-by-query/6735/4 "2017-07-06T03:38:56Z")

</div>


