RE: Custom indexer: deleteDocument() doesn't delete objects from index

Jan Tošovský, modified 5 Years ago. Liferay Master Posts: 576 Join Date: 7/22/10 Recent Posts
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
@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));
    }
thumbnail
Amos Fong, modified 5 Years ago. Liferay Legend Posts: 2047 Join Date: 10/7/08 Recent Posts
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]
Jan Tošovský, modified 5 Years ago. Liferay Master Posts: 576 Join Date: 7/22/10 Recent Posts
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?
Jan Tošovský, modified 5 Years ago. Liferay Master Posts: 576 Join Date: 7/22/10 Recent Posts
I refactored method so I am not interested if object exists in ES any more.