Wojciech Laka
Wojciech Laka

Reputation: 43

Lucene 6 How to avoid duplicate entries

Story: I need to search for a list of transactionIds be a given username query e.g "Peter M*".

Question: How is it possible to keep the stored transactionIds unique?

I have populated my index with following documents:

Document doc = new Document();
doc.add(new StoredField(TRANSACTION_ID, data.getTransactionId()));
doc.add(new TextField(MARCHANT_NAME, data.getName(), Store.NO));

I have tried allready two strategies (to avoid duplicate entries) to add a new entry.

  1. IndexWriter.updateDocument with a Term holding the transactionId to store.
  2. Search for the current transactionId, delete it and store it:

Upvotes: 0

Views: 877

Answers (1)

femtoRgon
femtoRgon

Reputation: 33341

You are using a StoredField for the TRANSACTION_ID field. That means it can be retrieved from the index, but is not indexed and can't be searched, and as such, it can't be used as a key to updateDocument. Use a StringField, instead.

Upvotes: 1

Related Questions