Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6832945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:55:13+00:00 2026-05-26T22:55:13+00:00

To delete a document on Lucene, there is the function indexWriter.deleteDocuments(…) with Query and/or

  • 0

To delete a document on Lucene, there is the function indexWriter.deleteDocuments(…) with Query and/or Terms.
That works fine.

However, I’d need to browse a collection of documents, and delete some of them based on a condition.
I could add a unique id field in the Document, and call indexWriter.deleteDocuments(…) based on this unique id.
However, I’d like to avoid this option, and do something like this instead:

TopDocs hits = indexSearcher.search(...);
for (ScoreDoc scoreDoc : hits.scoreDocs) {
   Document doc = indexSearcher.doc(scoreDoc.doc);
   if (...) {
      indexWriter.delete(doc);   // or similar
   }
}

Is it possible to do that?

ps: Again, I am aware that I could add a unique id field in the document,
and delete the document inside the loop by calling indexWriter.deleteDocuments(…) based on this unique id.
That would work fine. However, I am asking if it is possible to do it without this option.
Please do not answer about whether this is or is not the right approach. It is an interesting discussion, but it is not the objective of this post.
Please answer only about if it is possible (and how) or not to do without adding a unique id.

pss: I know I am repeating myself, but I’ll tell it again, because I fear that I will get answers not related to the objective of this post.
really, please focus only about if it is possible (and how) or not to do without adding a unique id.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:55:14+00:00Added an answer on May 26, 2026 at 10:55 pm

    You can come at it from the IndexReader instead.

    TopDocs hits = indexSearcher.search(...);
    for (ScoreDoc scoreDoc : hits.scoreDocs) {
       Document doc = indexSearcher.doc(scoreDoc.doc);
       if (...) {
          indexSearcher.getIndexReader().deleteDocument(doc);
       }
    }
    

    It won’t work if you have an IndexWriter already open on the Directory, though, so perhaps it’s not applicable to your case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to delete a document in lucene 2.4 with java. My code is
I am trying to delete a document by using a term in lucene index.
I need to perform deletion of the document from lucene search index. Standard approach
I have the following code $(document).ready(function(){ // class exists if($('.delete').length) { // add click
I have this and it works fine: $(document).ready( highlightTableRow ); but when I add
I have a html document and I want to delete all the divs of
If I create a cookie in Javascript document.cookie = 'unseen' how do I delete
i have problem use link_to_remote link_to_remote document example say link_to_remote Delete this post, :update
$(.delete).click( function() { var thesender = this; $(thesender).text(Del...); $.getJSON(ajax.php, {}, function(data) { if (data[result])
I erroneously delete all the rows from a MS SQL 2000 table that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.