Tasks
Learn how to work with asynchronous Elasticsearch operations to process documents in a non-blocking manner
When performing bulk operations - reindexing, query-based updating or deletions - a parameter may be provided which allows the job to run in a non-blocking manner. The method that Elasticsearch uses to monitor the completion of these jobs is called a task. In the reindex
, updateByQuery
, and deleteByQuery
methods of the client, the argument waitForCompletion
may be passed. When set to false a Task
object can be returned which will provide the status of the task and allow you to refresh through completion.
An example, using the reindex method and flushing the status output to the browser, might look something like:
The isComplete
method also accepts an argument of delay
to slow down the rate at which it re-checks the completion of the task. Using the above example, we could check only every 5 seconds by passing 5000 milliseconds as the delay
argument:
At times a reindex process may be marked as complete, but the documents were not transfered. In CBElasticsearch v2.2.5+, you can use reindexTask.getError()
to check for errors running the reindex script.
For older CBElasticsearch versions, inspect the document counts to determine if a reindex or update script failed:
getResponse()
will contain the error details when a script fails on specific documents. For more broad syntax or script-level errors, the error may only be contained in the newer getError()
payload in newer versions of CBElasticsearch.
When managing large indexes, a task-based approach to bulk operations can allow you to optimize the resource usage of both your Elasticsearch and CFML Application servers.
Last updated