Unable to delete document from index using java api?


(Sam-4) #1

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:

     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


(Shay Banon) #2

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 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:

    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


(Sam-4) #3

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 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 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:

    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


(system) #4