Legacy Knowledge Base
Published Jul. 2, 2025

Reindexing with script

Written By

József Géczi

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • As a developer, I would like to trigger reindex on my portal using a script, instead of running it via UI. This would for example bring the benefits of schedulable reindexing.

Environment

  • Liferay DXP 7.1
  • Liferay DXP 7.2
  • Liferay DXP 7.3

Resolution

Indeed, there is no 'official recommendation' exist about triggering reindexing via scripts, CLI/shell commands, nor API calls.

However, this sample Groovy script may be used in order to get closer to such expectations (Scripts can run at menu Server Administration -> Script):

def companyId = com.liferay.portal.kernel.util.PortalUtil.getCompanyId(actionRequest);def userId = java.lang.Long.parseLong(userInfo.get("liferay.user.id"));
com.liferay.portal.kernel.search.IndexWriterHelperUtil.reindex(userId, "reindex", [companyId] as long[], null);

The script above reindexes one particular company, from where the script has been executed. Although, using PortalUtil.getCompanyId() it should be possible to trigger the reindex on all the required companyId.

During reindex, expect the following warnings which may appear in Liferay logs:

org.apache.tika.config.InitializableProblemHandler$3 handleInitializableProblem
WARNING: TIFFImageWriter not loaded. tiff files will not be processed
See https://pdfbox.apache.org/2.0/dependencies.html#jai-image-io
for optional dependencies.
J2KImageReader not loaded. JPEG2000 files will not be processed.
See https://pdfbox.apache.org/2.0/dependencies.html#jai-image-io
for optional dependencies.

org.apache.tika.config.InitializableProblemHandler$3 handleInitializableProblem
WARNING: org.xerial's sqlite-jdbc is not loaded.
Please provide the jar on your classpath to parse sqlite files.
See tika-parsers/pom.xml for the correct version.

After understanding the reindex may not have effect on the highlighted type of files - such behavior is intended -, these warnings may be safely ignored.

Additional Information

  • Please note: Such custom scripts may only be applied in production at your own discretion, after thorough testing.
Did this article resolve your issue ?

Legacy Knowledge Base