legacy-knowledge-base
公開されました Jun. 30, 2025

Reindexing Large Volume of Document and Media into batches

投稿者

Apsara Raheja

knowledge-article-header-disclaimer-how-to

knowledge-article-header-disclaimer

legacy-article

learn-legacy-article-disclaimer-text

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