# Unable to delete document from index using java api?

**URL:** <https://discuss.elastic.co/t/unable-to-delete-document-from-index-using-java-api/5755>\
**Category:** Elasticsearch\
**Created:** [November 3, 2011, 6:02am UTC](https://discuss.elastic.co/t/unable-to-delete-document-from-index-using-java-api/5755 "2011-11-03T06:02:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_4](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sam\_4](https://discuss.elastic.co/u/Sam_4)\
**Post date:** [November 3, 2011, 6:02am UTC](https://discuss.elastic.co/t/unable-to-delete-document-from-index-using-java-api/5755/1 "2011-11-03T06:02:54Z")

</div>

Hi

My index contain following data:

## RecordId Name Address Age

## 1 abc xxx1 11 2 def xxx2 12 3 ghi xxx3 13 4 jkl xxx4 14 5 mno xxx5 15

I want to delete record from index with record id 1 but it doesn't  
work for me. i tried with two different method to delete document from  
index.

code:

1. 

```
     DeleteResponse deleteresponse =

```

client.prepareDelete(indexName, indexType, uniqueId)  
.setRefresh(true)  
.execute()  
.actionGet();  
System.out.println(deleteresponse.isNotFound()); //got true  
value

1. 

```
 DeleteRequestBuilder prepareDelete = client.prepareDelete();
 DeleteRequestBuilder deleteRequest =

```

prepareDelete.setIndex(indexName).setType(indexType).setId(uniqueId).setRefresh(true);  
DeleteResponse deleteresponse =  
deleteRequest.execute().actionGet();  
System.out.println(deleteresponse.isNotFound()); //got  
true value

please help me.

Thanks

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 3, 2011, 5:31pm UTC](https://discuss.elastic.co/t/unable-to-delete-document-from-index-using-java-api/5755/2 "2011-11-03T17:31:00Z")

</div>

Are you sure the index contains that document? What happens when you get it?

On Thu, Nov 3, 2011 at 8:02 AM, sam [mishra.sameek@gmail.com](mailto:mishra.sameek@gmail.com) wrote:

> Hi
> 
> My index contain following data:
> 
> ## RecordId Name Address Age
> 
> ## 1 abc xxx1 11 2 def xxx2 12 3 ghi xxx3 13 4 jkl xxx4 14 5 mno xxx5 15
> 
> I want to delete record from index with record id 1 but it doesn't  
> work for me. i tried with two different method to delete document from  
> index.
> 
> code:
> 
> 1. 
> 
> ```
> DeleteResponse deleteresponse =
> 
> ```
> 
> client.prepareDelete(indexName, indexType, uniqueId)  
> .setRefresh(true)  
> .execute()  
> .actionGet();  
> System.out.println(deleteresponse.isNotFound()); //got true  
> value
> 
> 1. 
> 
> ```
> DeleteRequestBuilder prepareDelete = client.prepareDelete();
> DeleteRequestBuilder deleteRequest =
> 
> ```
> 
> prepareDelete.setIndex(indexName).setType(indexType).setId(uniqueId).setRefresh(true);  
> DeleteResponse deleteresponse =  
> deleteRequest.execute().actionGet();  
> System.out.println(deleteresponse.isNotFound()); //got  
> true value
> 
> please help me.
> 
> Thanks

---

<div class="post-metadata">

**Author:** ![Sam\_4](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sam\_4](https://discuss.elastic.co/u/Sam_4)\
**Post date:** [November 4, 2011, 4:42am UTC](https://discuss.elastic.co/t/unable-to-delete-document-from-index-using-java-api/5755/3 "2011-11-04T04:42:50Z")

</div>

I got the problem,i have made mistake, i'm not define Document  
id,because it's not having id then it not able to delete the  
document.

Thanks

On Nov 3, 10:31 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Are you sure the index contains that document? What happens when you get it?
> 
> On Thu, Nov 3, 2011 at 8:02 AM, sam [mishra.sam...@gmail.com](mailto:mishra.sam...@gmail.com) wrote:
> 
> > Hi
> 
> > My index contain following data:
> 
> > ## RecordId Name Address Age
> > 
> > ## 1 abc xxx1 11 2 def xxx2 12 3 ghi xxx3 13 4 jkl xxx4 14 5 mno xxx5 15
> 
> > I want to delete record from index with record id 1 but it doesn't  
> > work for me. i tried with two different method to delete document from  
> > index.
> 
> > code:
> 
> > 1.
> 
> > ```
> > DeleteResponse deleteresponse =
> > 
> > ```
> > 
> > client.prepareDelete(indexName, indexType, uniqueId)  
> > .setRefresh(true)  
> > .execute()  
> > .actionGet();  
> > System.out.println(deleteresponse.isNotFound()); //got true  
> > value
> 
> > 1. 
> > 
> > ```
> > DeleteRequestBuilder prepareDelete = client.prepareDelete();
> > DeleteRequestBuilder deleteRequest =
> > 
> > ```
> 
> > prepareDelete.setIndex(indexName).setType(indexType).setId(uniqueId).setRef resh(true);  
> > DeleteResponse deleteresponse =  
> > deleteRequest.execute().actionGet();  
> > System.out.println(deleteresponse.isNotFound()); //got  
> > true value
> 
> > please help me.
> 
> > Thanks

---

<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:49am UTC](https://discuss.elastic.co/t/unable-to-delete-document-from-index-using-java-api/5755/4 "2017-07-06T03:49:54Z")

</div>


