PSK
PSK

Reputation: 367

Are docids constant if the index is not manipulated in Lucene 8.6.1?

Say I update my index once a day, everyday, at the same time. During the time between updates (for 21 hours or so), will the docids remain constant?

Upvotes: 1

Views: 108

Answers (1)

RonC
RonC

Reputation: 33881

As @andrewjames mentioned, the docId's only change when a merge happens. The docsId is basically the array index position of the doc in a particular segment.

The side effect of that is also that if you have multiple segments, then a given docId might be assigned to multiple docs, one in one segment, one in another segment, etc. If that's a problem, you can do a force merge once you are done building your index so that there is only a single segment. Then no two docs will have the same docId at that point.

The docId for a given document will not change if a merge does not happen. And a merge won't happen unless you call force merge or add or delete documents, or upgrade your index.

So...if you build your index, and don't add docs, delete docs, or call force merge, or upgrade your index then the docIds will be stable. But the next time you build your index, a give doc may receive a totally different doc Id. And as @andrewjames said, the docId assignments and timing of assignments are an internal affair in Lucene, so you sould be cautious about relying on them even when you know when and how they are currently assigned.

Upvotes: 1

Related Questions