# Java es 8+ client tasks api

**URL:** https://discuss.elastic.co/t/java-es-8-client-tasks-api/366996
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [September 23, 2024, 9:16pm UTC](https://discuss.elastic.co/t/java-es-8-client-tasks-api/366996 "2024-09-23T21:16:44Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mreeew](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mreeew/32/137463_2.png) [@mreeew](https://discuss.elastic.co/u/mreeew)
#### Post date: [September 23, 2024, 9:16pm UTC](https://discuss.elastic.co/t/java-es-8-client-tasks-api/366996/1 "2024-09-23T21:16:44Z")

</div>

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)

---

<div class="post-metadata">

### Author: ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)
#### Post date: [September 24, 2024, 12:35pm UTC](https://discuss.elastic.co/t/java-es-8-client-tasks-api/366996/2 "2024-09-24T12:35:46Z")

</div>

From #Elastic Search to #Elasticsearch

---

<div class="post-metadata">

### Author: ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)
#### Post date: [September 24, 2024, 12:36pm UTC](https://discuss.elastic.co/t/java-es-8-client-tasks-api/366996/3 "2024-09-24T12:36:02Z")

</div>

Added #language-clients

---

<div class="post-metadata">

### Author: ![ltrotta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ltrotta/32/124003_2.png) [@ltrotta](https://discuss.elastic.co/u/ltrotta)
#### Post date: [September 25, 2024, 4:20pm UTC](https://discuss.elastic.co/t/java-es-8-client-tasks-api/366996/4 "2024-09-25T16:20:30Z")

</div>

Hello and welcome! Those you're referring to are 2 different APIs, one is [Task management](https://www.elastic.co/guide/en/elasticsearch/reference/current/tasks.html) (to check on running tasks) and the other is [Update by Query](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html). An example of how to call Update by Query in the new client:

```java
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:

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

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 23, 2024, 4:20pm UTC](https://discuss.elastic.co/t/java-es-8-client-tasks-api/366996/5 "2024-10-23T16:20:56Z")

</div>

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