lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ivan Vasilev <>
Subject writer.tryDeleteDocument(..) does not delete document
Date Wed, 31 Oct 2012 15:41:09 GMT
Hy Guys,

I use as suggested in question "Lucene 4.0 delete by ID" from 29.Oct - 
instead of reader.delete(docID) use - writer.tryDeleteDocument(..) 
method but for some reason it does not work.

My code is:

         <Here create an index with 3 docs in it>

         IndexWriterConfig iwc = new 
IndexWriterConfig(Version.LUCENE_40, new 
         IndexWriter writer = new IndexWriter(indexDir, iwc);
         IndexReader nrtReader =, false); // 
using "true" gives the same result
         writer.tryDeleteDocument(nrtReader, 1); // using 
nrtReader.leaves().get(0).reader() gives the same result (I have only 
one segment)

         IndexReader ir =;
         System.out.println("ir.numDeletedDocs(): " + ir.numDeletedDocs());
         Bits liveDocs = MultiFields.getLiveDocs(ir);
         System.out.println("liveDocs: " + liveDocs);


The output is:

ir.numDeletedDocs(): 0
liveDocs: null


This is just simple test - no merges or adding new docs after creation 
of the index.

I need deleting by Lucene ID because we have Parallel Indexes and when 
deleting document I should delete the related documents from both 
indexes. So when having to delete some document I will have Term(s) that 
are only in one of the indexes of the parallel index and can use 
writer.deleteDocuments(term), but this will not help for the other index 
in same Parallel Index. So I will have to find docs matching the Term(s) 
and delete them in all sub-indexes of the Parallel Index.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message