<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Re-index doesnt delete old indexes for Layouts in Elastisearch server</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=96835070" />
  <subtitle>Re-index doesnt delete old indexes for Layouts in Elastisearch server</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=96835070</id>
  <updated>2026-04-06T22:03:55Z</updated>
  <dc:date>2026-04-06T22:03:55Z</dc:date>
  <entry>
    <title>RE: Re-index doesnt delete old indexes for Layouts in Elastisearch server</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111079004" />
    <author>
      <name>Leo Volkov</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111079004</id>
    <updated>2018-10-01T22:55:04Z</updated>
    <published>2018-10-01T22:55:04Z</published>
    <summary type="html">&lt;p&gt;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&lt;/p&gt;</summary>
    <dc:creator>Leo Volkov</dc:creator>
    <dc:date>2018-10-01T22:55:04Z</dc:date>
  </entry>
  <entry>
    <title>RE: Re-index doesnt delete old indexes for Layouts in Elastisearch server</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=96845127" />
    <author>
      <name>Jorge Diaz</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=96845127</id>
    <updated>2017-10-13T10:19:53Z</updated>
    <published>2017-10-13T10:19:53Z</published>
    <summary type="html">&lt;div class="quote-title"&gt;Soumyashree Mishra:&lt;/div&gt;&lt;blockquote&gt;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&amp;#39;t the delete operation call the delete logic of the LayoutIndexer?.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;In Liferay, out of the box,  Layout has no any indexer, so it is not necessary for Layout service to call index functionality.&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;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)</summary>
    <dc:creator>Jorge Diaz</dc:creator>
    <dc:date>2017-10-13T10:19:53Z</dc:date>
  </entry>
  <entry>
    <title>RE: Re-index doesnt delete old indexes for Layouts in Elastisearch server</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=96839130" />
    <author>
      <name>Soumyashree Mishra</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=96839130</id>
    <updated>2017-10-13T07:42:20Z</updated>
    <published>2017-10-13T07:42:20Z</published>
    <summary type="html">&lt;blockquote&gt;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&lt;br /&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;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&amp;#39;t the delete operation call the delete logic of the LayoutIndexer?&lt;br /&gt;&lt;br /&gt;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.</summary>
    <dc:creator>Soumyashree Mishra</dc:creator>
    <dc:date>2017-10-13T07:42:20Z</dc:date>
  </entry>
  <entry>
    <title>RE: Re-index doesnt delete old indexes for Layouts in Elastisearch server</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=96838408" />
    <author>
      <name>Jorge Diaz</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=96838408</id>
    <updated>2017-10-13T06:22:11Z</updated>
    <published>2017-10-13T06:22:11Z</published>
    <summary type="html">When you implement a indexer, you also have to call reindex/delete logic from the code that creates/modifies/deletes the object, see: &lt;a href="https://dev.liferay.com/es/develop/tutorials/-/knowledge_base/7-0/handling-indexing-in-the-guestbook-service-layer"&gt;https://dev.liferay.com/es/develop/tutorials/-/knowledge_base/7-0/handling-indexing-in-the-guestbook-service-layer&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;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</summary>
    <dc:creator>Jorge Diaz</dc:creator>
    <dc:date>2017-10-13T06:22:11Z</dc:date>
  </entry>
  <entry>
    <title>Re-index doesnt delete old indexes for Layouts in Elastisearch server</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=96835069" />
    <author>
      <name>Soumyashree Mishra</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=96835069</id>
    <updated>2017-10-13T05:32:18Z</updated>
    <published>2017-10-13T05:32:18Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hi All,&lt;br&gt;&lt;br&gt;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:&lt;br&gt;&lt;br&gt;05:20:09,370 ERROR [http-nio-8080-exec-6][render_portlet_jsp:131] null&lt;br&gt;com.liferay.portal.kernel.exception.NoSuchLayoutException: No Layout exists with the primary key 84834&lt;br&gt;	at com.liferay.portal.service.persistence.impl.LayoutPersistenceImpl.findByPrimaryKey(LayoutPersistenceImpl.java:11281)&lt;br&gt;	at com.liferay.portal.service.persistence.impl.LayoutPersistenceImpl.findByPrimaryKey(LayoutPersistenceImpl.java:11297)&lt;br&gt;	at com.liferay.portal.service.impl.LayoutLocalServiceImpl.getLayout(LayoutLocalServiceImpl.java:1154)&lt;br&gt;	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:163)&lt;br&gt;	at com.liferay.portal.service.impl.LayoutLocalServiceStagingAdvice.invoke(LayoutLocalServiceStagingAdvice.java:137)&lt;br&gt;	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:137)&lt;br&gt;	at com.liferay.portal.spring.transaction.DefaultTransactionExecutor.execute(DefaultTransactionExecutor.java:54)&lt;br&gt;	at com.liferay.portal.spring.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:58)&lt;br&gt;	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:137)&lt;br&gt;	at com.liferay.portal.spring.aop.ChainableMethodAdvice.invoke(ChainableMethodAdvice.java:56)&lt;br&gt;	at com.liferay.portal.spring.aop.ServiceBeanMethodInvocation.proceed(ServiceBeanMethodInvocation.java:137)&lt;br&gt;	at com.liferay.portal.spring.aop.ServiceBeanAopProxy.invoke(ServiceBeanAopProxy.java:169)&lt;br&gt;	at com.liferay.layout.admin.web.internal.asset.LayoutAssetRendererFactory.getAssetRenderer(LayoutAssetRendererFactory.java:88)&lt;br&gt;	at com.liferay.asset.kernel.model.BaseAssetRendererFactory.getAssetRenderer(BaseAssetRendererFactory.java:71)&lt;br&gt;	at org.apache.jsp.search_jsp._jspService(search_jsp:1022)&lt;br&gt;	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)&lt;br&gt;	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)&lt;br&gt;	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)&lt;br&gt;	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)&lt;br&gt;	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)&lt;br&gt;&lt;br&gt;&lt;strong&gt;LayoutIndexer Class.&lt;/strong&gt; Is there something  i am missing here? &lt;br&gt;&lt;pre&gt;&lt;code&gt;
public class LayoutIndexer extends BaseIndexer&amp;lt;layout&amp;gt; {

	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);
	}
}&amp;lt;/layout&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;In addition, deleting a layout in Liferay doesn't  delete that corresponding index as opposed to creating a layout.&lt;br&gt;I am currently working on Liferay DXP SP3 version with the embedded elastisearch server.&lt;br&gt;&lt;br&gt;Regards,&lt;br&gt;Soumya&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Soumyashree Mishra</dc:creator>
    <dc:date>2017-10-13T05:32:18Z</dc:date>
  </entry>
</feed>
