Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Custom indexer: deleteDocument() doesn't delete objects from index
Any idea why deleteDocument() method keeps my objects in the index? There is no error thrown. It is not removed even after some period.
This method is invoked when reindexing my objects, e.g. from Control Panel | Search. My goal is to remove entries matching specific conditions. If conditions are met, doDelete() is invoked. However, when calling getDocument(webHelpDocument) after this step, I'd expect null result.
I've tried also IndexWriterHelperUtil.deleteDocument() method, but I am getting same result.
LR 7.2.0 GA1
This method is invoked when reindexing my objects, e.g. from Control Panel | Search. My goal is to remove entries matching specific conditions. If conditions are met, doDelete() is invoked. However, when calling getDocument(webHelpDocument) after this step, I'd expect null result.
I've tried also IndexWriterHelperUtil.deleteDocument() method, but I am getting same result.
LR 7.2.0 GA1
@Override
protected void doReindex(String[] ids) throws Exception {
for (WebHelpDocument webHelpDocument : webHelpDocumentLocalService.getWebHelpDocuments(-1, -1)) {
if (condition) {
delete(webHelpDocument);
} else {
doReindex(webHelpDocument);
}
}
}
@Override
protected void doDelete(WebHelpDocument webHelpDocument) throws Exception {
Document documentOrig = getDocument(webHelpDocument);
String uuidOrig = documentOrig.get(Field.UID);
Document documentGenerated = new DocumentImpl();
documentGenerated.addUID(getClassName(), webHelpDocument.getDocumentId());
String uuidGenerated = documentGenerated.get(Field.UID);
LOGGER.info(uuidOrig.equals(uuidGenerated));
LOGGER.info("before deleting: " + webHelpDocument.getDocumentId() + " " + uuidGenerated + " " + uuidOrig + " " + isCommitImmediately());
deleteDocument(webHelpDocument.getCompanyId(), webHelpDocument.getDocumentId());
LOGGER.info("after deleting (1): " + webHelpDocument.getDocumentId() + " " + (getDocument(webHelpDocument) != null));
IndexWriterHelperUtil.deleteDocument(getSearchEngineId(), webHelpDocument.getCompanyId(), uuidGenerated, true);
LOGGER.info("after deleting (2): " + webHelpDocument.getDocumentId() + " " + (getDocument(webHelpDocument) != null));
}
I think you should be deleting by uuidOrig (It's not clear whether it's the same or different than uuidGenerated though). Looks like you're extending BaseIndexer, is that right? How did you implement the doGetDocument? Are you indexing the companyId field in your document?Also, I would try checking ES directly to see if you got the companyId and uid correct. If it's embedded, try checking this URL:
http://localhost:9200/liferay-[companyId]/_search?q=[uid]
http://localhost:9200/liferay-[companyId]/_search?q=[uid]
Silly me, using method getDocument(webHelpDocument) I incorrectly assumed it returns indexed object from ES, but it actually builds the object on the fly from the passed object.
Is there any efficient way to check if indexed object exists in ES?
Is there any efficient way to check if indexed object exists in ES?
I refactored method so I am not interested if object exists in ES any more.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™