掲示板

Re-index doesnt delete old indexes for Layouts in Elastisearch server

6年前 に Soumyashree Mishra によって更新されました。

Re-index doesnt delete old indexes for Layouts in Elastisearch server

Junior Member 投稿: 32 参加年月日: 16/04/18 最新の投稿
Hi All,

I have created a Layout Indexer to make all the pages searchable. But when i delete a page and re-index the Layouts or all indexes, the index for the deleted page is not removed from the elastisearch server resulting in the below error while searching:

05:20:09,370 ERROR [http-nio-8080-exec-6][render_portlet_jsp:131] null
com.liferay.portal.kernel.exception.NoSuchLayoutException: No Layout exists with the primary key 84834
at com.liferay.portal.service.persistence.impl.LayoutPersistenceImpl.findByPrimaryKey(LayoutPersistenceImpl.java:11281)
at com.liferay.portal.service.persistence.impl.LayoutPersistenceImpl.findByPrimaryKey(LayoutPersistenceImpl.java:11297)
at com.liferay.portal.service.impl.LayoutLocalServiceImpl.getLayout(LayoutLocalServiceImpl.java:1154)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:163)
at com.liferay.portal.service.impl.LayoutLocalServiceStagingAdvice.invoke(LayoutLocalServiceStagingAdvice.java:137)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:137)
at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:54)
at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:58)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:137)
at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)
at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:137)
at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:169)
at com.liferay.layout.admin.web.internal.asset.LayoutAssetRendererFactory.getAssetRenderer(LayoutAssetRendererFactory.java:88)
at com.liferay.asset.kernel.model.BaseAssetRendererFactory.getAssetRenderer(BaseAssetRendererFactory.java:71)
at org.apache.jsp.search_jsp._jspService(search_jsp:1022)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)

LayoutIndexer Class. Is there something i am missing here?

public class LayoutIndexer extends BaseIndexer<layout> {

	private static final String CLASS_NAME = Layout.class.getName();
	private static final Log _log = LogFactoryUtil.getLog(LayoutIndexer.class);

	public LayoutIndexer() {

		setDefaultSelectedFieldNames(
			"layoutId", Field.COMPANY_ID, "friendlyUrl",
			Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.GROUP_ID,
			Field.MODIFIED_DATE, Field.SCOPE_GROUP_ID, Field.NAME, Field.UID);
		setFilterSearch(true);
		setPermissionAware(true);
	
	}
	
	@Override
	public String getClassName() {
		return CLASS_NAME;
	}

	@Override
	public void postProcessSearchQuery(BooleanQuery searchQuery, BooleanFilter fullQueryBooleanFilter,
			SearchContext searchContext) throws Exception {

		addSearchTerm(searchQuery, searchContext, "friendlyUrl", false);
		addSearchTerm(searchQuery, searchContext, "layoutId", false);
		addSearchTerm(searchQuery, searchContext, Field.NAME, true);
		super.postProcessSearchQuery(searchQuery, fullQueryBooleanFilter, searchContext);
	}
	
	@Override
	protected void doDelete(Layout layout) throws Exception {
		deleteDocument(layout.getCompanyId(), layout.getPlid());
		if (_log.isDebugEnabled()) {
			_log.debug("Deleting Layout " + layout.getNameCurrentValue());
		}

	}

	@Override
	protected Document doGetDocument(Layout layout) throws Exception {

		if (_log.isDebugEnabled()) {
			_log.debug("Indexing Layout " + layout);
		}

		Document document = getBaseModelDocument(CLASS_NAME , layout);

		document.addKeyword("friendlyUrl", layout.getFriendlyURL());
		document.addLocalizedKeyword(Field.NAME, layout.getNameMap());
		if (_log.isDebugEnabled()) {
			_log.debug("Document " + layout + " indexed successfully");
		}
		return document;
	}

	@Override
	protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletRequest portletRequest,
			PortletResponse portletResponse) throws Exception {
		Summary summary = createSummary(document);
		return summary;
	}

	@Override
	protected void doReindex(String className, long classPK) throws Exception {
		Layout layout = LayoutLocalServiceUtil.fetchLayout(classPK);
		
		doReindex(layout);
	}


	@Override
	protected void doReindex(Layout layout) throws Exception {
		if(!layout.getType().equals("node")){
			if(isIndexable(layout)){
				_log.debug("Adding Index for"+layout.getNameCurrentValue());
				Document document = getDocument(layout);
				
				IndexWriterHelperUtil.updateDocument(
						getSearchEngineId(), layout.getCompanyId(), document,
						isCommitImmediately());
			}else{
				_log.debug("Removing Index for"+layout.getNameCurrentValue());
				deleteDocument(layout.getCompanyId(), layout.getPlid());
			}
		}
	}
	
	@Override
	protected void doReindex(String[] ids) throws Exception {
		long companyId = GetterUtil.getLong(ids[0]);
		
		reIndexLayouts(companyId);
	}
}</layout>


In addition, deleting a layout in Liferay doesn't delete that corresponding index as opposed to creating a layout.
I am currently working on Liferay DXP SP3 version with the embedded elastisearch server.

Regards,
Soumya
thumbnail
6年前 に Jorge Díaz によって更新されました。

RE: Re-index doesnt delete old indexes for Layouts in Elastisearch server

Liferay Master 投稿: 753 参加年月日: 14/01/09 最新の投稿
When you implement a indexer, you also have to call reindex/delete logic from the code that creates/modifies/deletes the object, see: https://dev.liferay.com/es/develop/tutorials/-/knowledge_base/7-0/handling-indexing-in-the-guestbook-service-layer

In your case, as you are trying to index a Liferay object, you have two options: create a wrapper of Layout services or create a model listener and call reindex/delete from there
6年前 に Soumyashree Mishra によって更新されました。

RE: Re-index doesnt delete old indexes for Layouts in Elastisearch server

Junior Member 投稿: 32 参加年月日: 16/04/18 最新の投稿
When you implement a indexer, you also have to call reindex/delete logic from the code that creates/modifies/deletes the object, see: https://dev.liferay.com/es/develop/tutorials/-/knowledge_base/7-0/handling-indexing-in-the-guestbook-service-layer


In case of Layouts, all create and udpate operation calls the re-index logic of the LayoutIndexer, except for the delete operation. Is this the expected behavior? Shouldn't the delete operation call the delete logic of the LayoutIndexer?

I compared this behavior with that of JournalArticle and the re-index/delete logic of the corresponding Indexer is called after every create,update and delete operation on JournalArticle.
thumbnail
6年前 に Jorge Díaz によって更新されました。

RE: Re-index doesnt delete old indexes for Layouts in Elastisearch server

Liferay Master 投稿: 753 参加年月日: 14/01/09 最新の投稿
Soumyashree Mishra:
In case of Layouts, all create and udpate operation calls the re-index logic of the LayoutIndexer, except for the delete operation. Is this the expected behavior? Shouldn't the delete operation call the delete logic of the LayoutIndexer?.


In Liferay, out of the box, Layout has no any indexer, so it is not necessary for Layout service to call index functionality.

Layout service not calling delete index operation is not an error, the error is the unnecessary Layout service call to reindex functionality because there is no indexer.

If you want to add an Indexer and If you need to add missing delete/reindex calls, you have to extend the product (with a service wrapper or a model listener)
5年前 に Leo Volkov によって更新されました。

RE: Re-index doesnt delete old indexes for Layouts in Elastisearch server

New Member 投稿: 7 参加年月日: 12/11/30 最新の投稿

In liferay7 as hooks are no longer supported , how to write this indexer ? will it be a service Wrapper , if so what is the Service name to give  (com.liferay.portal.kernal.service.LayoutLocalServiceWrapper)? I am using eclipse .  Thank you