Search by DocID instead of ID when deleting old documents

The method IndexingHelper#deleteOldDocuments() is responsible for removing
old search entries, and it seems that it can find these old entries correctly
(the docIdList correctly contains old entries).

But the deleteByQuery() call seems to be searching the wrong column (with the
default settings, it is searching by "_id" column instead of "doc_id").

This patch changes the QueryBuilder (used by deleteByQuery) from querying
by "_id" column to "doc_id" instead.
This commit is contained in:
hieu1.hoangtrung 2023-12-11 11:29:09 +07:00
parent 613c418631
commit 15e48aded1

View file

@ -121,8 +121,7 @@ public class IndexingHelper {
}
if (!docIdList.isEmpty()) {
searchEngineClient.deleteByQuery(fessConfig.getIndexDocumentUpdateIndex(),
QueryBuilders.idsQuery().addIds(docIdList.stream().toArray(n -> new String[n])));
QueryBuilders.termsQuery(fessConfig.getIndexFieldDocId(), docIdList.stream().toArray(n -> new String[n])));
}
}
@ -145,7 +144,7 @@ public class IndexingHelper {
public long deleteDocumentsByDocId(final SearchEngineClient searchEngineClient, final List<String> docIdList) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
return searchEngineClient.deleteByQuery(fessConfig.getIndexDocumentUpdateIndex(),
QueryBuilders.idsQuery().addIds(docIdList.stream().toArray(n -> new String[n])));
QueryBuilders.termsQuery(fessConfig.getIndexFieldDocId(), docIdList.stream().toArray(n -> new String[n])));
}
public long deleteDocumentByQuery(final SearchEngineClient searchEngineClient, final QueryBuilder queryBuilder) {