Indexing Queue

Once you integrate the Search add-on into your application, it immediately begins monitoring changes in your entities. This section details the process of configuring the automatic update of indexes with the latest data.

The change tracking mechanism stores a queue of actions that should be done for changed entity instances in the SEARCH_INDEXING_QUEUE database table. The IndexingQueueManager bean contains methods to process the queue and send changed data to Elasticsearch/OpenSearch.

It’s essential to establish regular processing of the indexing queue to ensure that search results reflect current data.

For scheduling periodic queue processing, you can utilize the Quartz Job Scheduler following the instructions provided.

Default Quartz Configuration

The Search add-on comes with a pre-configured Quartz job for regularly processing the indexing queue. To enable this feature, follow these steps:

  1. Include the Quartz add-on in your project as described in the Quartz / Installation section.

  2. Modify the CRON expression as needed. The default value is 0/5 * * * * ? (every 5 seconds).

    jmix.search.indexing-queue-processing-cron = 0/10 * * * * ?

The default configuration creates and schedules a job with the IndexingQueueProcessing identity.

Custom Quartz Configuration

If you prefer to utilize a custom Quartz configuration, follow these steps:

  1. Include the Quartz add-on in your project as described in the Quartz / Installation section.

  2. Within the application.properties file, include the following property to deactivate the default configuration:

    jmix.search.use-default-indexing-queue-processing-quartz-configuration = false
  3. Develop a custom job class that invokes IndexingQueueManager.processNextBatch():

    public class MyCustomQueueProcessingJob implements Job {
    
        @Autowired
        private IndexingQueueManager indexingQueueManager;
    
        @Override
        public void execute(JobExecutionContext context) throws JobExecutionException {
            indexingQueueManager.processNextBatch();
        }
    }
  4. While the application is running, navigate to the Quartz → Quartz jobs view to set up a job for the MyCustomQueueProcessingJob class.

  5. Alternatively, if you want to configure the job during development, register the following beans in the application:

    @Bean
    JobDetail myCustomIndexingQueueProcessingJob() {
        return JobBuilder.newJob()
                .ofType(IndexingQueueProcessingJob.class)
                .storeDurably()
                .withIdentity("MyCustomIndexingQueueProcessing")
                .build();
    }
    
    @Bean
    Trigger myCustomIndexingQueueProcessingTrigger() {
        return TriggerBuilder.newTrigger()
                .forJob(myCustomIndexingQueueProcessingJob())
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
                .build();
    }