# Deleting a specific document in an index

**URL:** <https://discuss.elastic.co/t/deleting-a-specific-document-in-an-index/60299>\
**Category:** Elasticsearch\
**Created:** [September 12, 2016, 1:54pm UTC](https://discuss.elastic.co/t/deleting-a-specific-document-in-an-index/60299 "2016-09-12T13:54:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shailen](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Shailen](https://discuss.elastic.co/u/Shailen)\
**Post date:** [September 12, 2016, 1:54pm UTC](https://discuss.elastic.co/t/deleting-a-specific-document-in-an-index/60299/1 "2016-09-12T13:54:14Z")

</div>

I generated 2 documents with the following curl command:

curl -XPOST '[http://PICDSM020001125.intranet.barcapint.com:9200/stuckthreads/detail?pretty](http://PICDSM020001125.intranet.barcapint.com:9200/stuckthreads/detail?pretty)' -d '  
{  
"date":"2016-09-09T14:00:00",  
"environment":"UAT3",  
"slotCount":1,  
"slotAverage":292,  
"maxCount":0,  
"maxAverage":0  
}'  
curl -XPOST '[http://PICDSM020001125.intranet.barcapint.com:9200/stuckthreads/detail?pretty](http://PICDSM020001125.intranet.barcapint.com:9200/stuckthreads/detail?pretty)' -d '  
{  
"date":"2016-09-09T14:00:00",  
"environment":"STAGE",  
"slotCount":1,  
"slotAverage":352,  
"maxCount":0,  
"maxAverage":0  
}'

I then deleted the first document with the following command:  
curl -XDELETE '[http://PICDSM020001125.intranet.barcapint.com:9200/stuckthreads/\_query](http://PICDSM020001125.intranet.barcapint.com:9200/stuckthreads/_query)' -d '  
{  
"query" : {  
"term" : {  
"date" : "2016-09-09T14:00:00",  
"environment":"UAT3"  
}  
}  
}'

but both the documents got deleted. Is there something I am doing wrong?

---

<div class="post-metadata">

**Author:** ![dkspace](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@dkspace](https://discuss.elastic.co/u/dkspace)\
**Post date:** [September 12, 2016, 1:58pm UTC](https://discuss.elastic.co/t/deleting-a-specific-document-in-an-index/60299/2 "2016-09-12T13:58:07Z")

</div>

> [@Shailen](#):
>
> seems second time you updated document but not created second one.

try  
curl -XPOST '[http://PICDSM020001125.intranet.barcapint.com:9200/stuckthreads/1](http://PICDSM020001125.intranet.barcapint.com:9200/stuckthreads/1)  
{......}  
curl -XPOST '[http://PICDSM020001125.intranet.barcapint.com:9200/stuckthreads/2](http://PICDSM020001125.intranet.barcapint.com:9200/stuckthreads/2)  
{....}  
for example  
PUT /index\_name/type/1  
{  
"@timestamp" : "2016-09-12",  
"value": 9999.01  
}

---

<div class="post-metadata">

**Author:** ![Shailen](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Shailen](https://discuss.elastic.co/u/Shailen)\
**Post date:** [September 12, 2016, 2:03pm UTC](https://discuss.elastic.co/t/deleting-a-specific-document-in-an-index/60299/3 "2016-09-12T14:03:23Z")

</div>

well when I do a get I see 2 hits i.e. two documents.

10:03:07/nypntdev@nykdsr5838:~/logs/kibana\_stuck\_threads/tmp]$ curl -i -XGET '[http://PICDSM020001125.intranet.barcapint.com:9200/stuckthreads/\_search?pretty](http://PICDSM020001125.intranet.barcapint.com:9200/stuckthreads/_search?pretty)'  
HTTP/1.1 200 OK  
Content-Type: application/json; charset=UTF-8  
Content-Length: 745  
Proxy-Connection: Keep-Alive  
Connection: Keep-Alive  
Date: Mon, 12 Sep 2016 14:03:10 GMT

{  
"took" : 1,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 2,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "stuckthreads",  
"\_type" : "detail",  
"\_id" : "AVcetWmaZZ3pMcf82Xd2",  
"\_score" : 1.0,  
"\_source":  
{  
"date":"2016-09-09T14:00:00",  
"environment":"STAGE",  
"slotCount":1,  
"slotAverage":352,  
"maxCount":0,  
"maxAverage":0  
}  
}, {  
"\_index" : "stuckthreads",  
"\_type" : "detail",  
"\_id" : "AVcetWmLZZ3pMcf82Xd1",  
"\_score" : 1.0,  
"\_source":  
{  
"date":"2016-09-09T14:00:00",  
"environment":"UAT3",  
"slotCount":1,  
"slotAverage":292,  
"maxCount":0,  
"maxAverage":0  
}  
} ]  
}  
}

---

<div class="post-metadata">

**Author:** ![Shailen](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Shailen](https://discuss.elastic.co/u/Shailen)\
**Post date:** [September 12, 2016, 2:07pm UTC](https://discuss.elastic.co/t/deleting-a-specific-document-in-an-index/60299/4 "2016-09-12T14:07:07Z")

</div>

so - is it using date as a key to the document? is there a way I can use date and environment as the key so the delete will only work on that document?

---

<div class="post-metadata">

**Author:** ![dkspace](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@dkspace](https://discuss.elastic.co/u/dkspace)\
**Post date:** [September 12, 2016, 2:08pm UTC](https://discuss.elastic.co/t/deleting-a-specific-document-in-an-index/60299/5 "2016-09-12T14:08:23Z")

</div>

[quote="Shailen, post:3, topic:60299"]  
delete by id[/quote]  
try DELETE /stuckthreads/detail/AVcetWmaZZ3pMcf82Xd2

my example DELETE logstash-2016.09.12/fluentd/AVcet4k90SCsdvTqOSgO is OK

---

<div class="post-metadata">

**Author:** ![Shailen](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Shailen](https://discuss.elastic.co/u/Shailen)\
**Post date:** [September 12, 2016, 2:12pm UTC](https://discuss.elastic.co/t/deleting-a-specific-document-in-an-index/60299/6 "2016-09-12T14:12:53Z")

</div>

here is the problem with that approach. I don't know the id I want to delete in advance since it is auto-generated. I only the date and environment.

---

<div class="post-metadata">

**Author:** ![Shailen](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Shailen](https://discuss.elastic.co/u/Shailen)\
**Post date:** [September 12, 2016, 2:39pm UTC](https://discuss.elastic.co/t/deleting-a-specific-document-in-an-index/60299/7 "2016-09-12T14:39:25Z")

</div>

can someone please help with an alternate solution?

---

<div class="post-metadata">

**Author:** ![Shailen](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Shailen](https://discuss.elastic.co/u/Shailen)\
**Post date:** [September 12, 2016, 5:34pm UTC](https://discuss.elastic.co/t/deleting-a-specific-document-in-an-index/60299/8 "2016-09-12T17:34:57Z")

</div>

after trying a couple of options, the following command worked:

curl -XDELETE '[http://PICDSM020001125.intranet.barcapint.com:9200/stuckthreads/\_query?q=%2Bdate%3A"2016-09-09T14:00:00"+%2Benvironment%3A"UAT3"](http://PICDSM020001125.intranet.barcapint.com:9200/stuckthreads/_query?q=%2Bdate%3A%222016-09-09T14:00:00%22+%2Benvironment%3A%22UAT3%22)'

---

<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 5, 2017, 10:21pm UTC](https://discuss.elastic.co/t/deleting-a-specific-document-in-an-index/60299/9 "2017-07-05T22:21:01Z")

</div>


