Indexing Queue
As soon as you include the Search add-on in your application, it starts tracking changes in your entities. In this section, we describe how to set up the automatic update of the Elasticsearch indexes with the new data.
The change tracking mechanism stores a queue of actions that should be done for changed entity instances in the the SEARCH_INDEXING_QUEUE
database table. The IndexingQueueManager
bean contains methods to process the queue and send changed data to Elasticsearch.
You should set up periodic processing of the indexing queue, otherwise the search will return stale data. |
You can use Quartz Job Scheduler for periodic queue processing as described below.
Default Quartz Configuration
The Search add-on provides the default configuration of the Quartz job for processing the indexing queue on a regular basis. To use it, do the following:
-
Include Quartz add-on in your project as described in the Quartz / Installation section.
-
Change the CRON expression if necessary. 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 want to use a custom Quartz configuration, do the following:
-
Include Quartz add-on in your project as described in the Quartz / Installation section.
-
Add the following property to the
application.properties
file to disable the default configuration:jmix.search.use-default-indexing-queue-processing-quartz-configuration = false
-
Create 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(); } }
-
In the running application, open the Administration → Quartz jobs screen, and configure a job for the
MyCustomQueueProcessingJob
class. -
Alternatively, if you want to configure the job at development time, 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(); }