Java es 8+ client tasks api

How to use tasks api in 8+ client in java?
I've seen ElasticSearchTasks client which provides functionality to list/cancel/get tasks. But how to send a task?
Previously we could just use submitUpdateByQueryTask method of restHighLevelClient which returns taskId.
But how to send a long running request and get taskId back now? (similar to wait_for_completion=false)

From Elastic Search to Elasticsearch

Added language-clients

Hello and welcome! Those you're referring to are 2 different APIs, one is Task management (to check on running tasks) and the other is Update by Query. An example of how to call Update by Query in the new client:

UpdateByQueryResponse ubqRes = esClient.updateByQuery(u -> u
    .waitForCompletion(false)
    .index("my-index-000001")
    .conflicts(Conflicts.Proceed)
    .query(q -> q
        .term(t -> t
            .field("user.id")
            .value("kimchy")
        )
    )
);

it returns an object that (in this case since wait_for_completion is false) will contain the task Id, which can then be checked by using a Get Task request:

GetTasksResponse taskInfo = esClient.tasks().get(g -> g.taskId(ubqRes.task()));
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.