Legacy Knowledge Base
Published Jun. 30, 2025

Reindexing Large Volume of Document and Media into batches

Written By

Apsara Raheja

How To articles are not official guidelines or officially supporteddocumentation. They are community-contributed content and may not alwaysreflect the latest updates to Liferay DXP. We welcome your feedback toimprove How to articles!

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

Legacy Article

You are viewing an article from our legacy "FastTrack"publication program, made available for informational purposes. Articlesin this program were published without a requirement for independentediting or verification and are provided "as is" withoutguarantee.

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

NOTE: The following resolution requires customization and should only be implemented at the discretion of your team. Liferay Support will not be able to assist with designing or implementing customizations.

Issue

  • How to reindex a large volume of documents since full reindexing takes a lot of time, which would not be feasible in the production environment?
  • Is it possible to reindex the documents part by part?

Environment

  • Liferay DXP 7.3+

Resolution

  • Here is the groovy script to perform a partial reindex of specific folders or files to minimize the resource usage:
    import com.liferay.portal.kernel.log.Log
    import com.liferay.portal.kernel.log.LogFactoryUtil
    import com.liferay.portal.kernel.search.IndexerRegistryUtil
    import com.liferay.portal.kernel.search.*
    import com.liferay.document.library.kernel.model.DLFileEntry
    import com.liferay.document.library.kernel.service.DLFileEntryLocalServiceUtil
    import com.liferay.portal.kernel.util.OrderByComparator;

    Log log = LogFactoryUtil.getLog("DOCUMENT_AND_MEDIA_REINDEXER")

    // Define repository (Group) ID and folder ID
    long repositoryId = 20121; // Replace with actual Site (Group) ID
    long folderId = 47159; // Replace with actual Folder ID
    int start = 0;
    int end = 6;
    OrderByComparator<DLFileEntry> orderByComparator = null; // Sorting can be added if needed

    // Fetch file entries with the correct method signature
    List<DLFileEntry> fileEntries = DLFileEntryLocalServiceUtil.getFileEntries(repositoryId, folderId, start, end, orderByComparator);
    log.info("Found " + fileEntries.size() + " file entries.");

    // Get the indexer instance for DLFileEntry
    Indexer<DLFileEntry> fileEntryIndexer = IndexerRegistryUtil.getIndexer(DLFileEntry.class);
    log.info("Reindexing Document and Media Entries");

    // Reindex each file entry individually
    for (DLFileEntry fileEntry : fileEntries) {
    log.info("FileEntryID Is: " + fileEntry.getFileEntryId());
    fileEntryIndexer.reindex(fileEntry);
    log.info("Reindexing finished for FileEntryID: " + fileEntry.getFileEntryId());
    }

    log.info("Reindexing process completed.");

 

Additional Information

  • Please ensure to test the script in lower environments first before proceeding with the production environment. 
  • Before running the script, take a backup of your database and document library files (within the data folder). 
  • Liferay DXP Searching/Indexing FAQ
Did this article resolve your issue ?

Legacy Knowledge Base