How to get the reindexation tasks with java opensearch client?

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):
Opensearch 2.4.1
opensearch-java 2.8.1
opensearch test-containers 2.0.1
opensearch-rest-client 2.11.1

Describe the issue:

Hello everyone,
First of all, I wish you a happy new year !
As for the matter at hand, I am currently trying to reduce the size of our opensearch, as it has gotten quite consequent over the years. To do so, I have a java 21 application that will get the list of all our indexes, and reindex them one at a time, to protect the memory and cpu, with a lighter mapping. I use the java-client on this link Java client - OpenSearch Documentation, as the java high-level rest client is supposed to be deprecated.
To check that an index is properly reindexed, I want to use the task api, as there is always a task that’s created when a reindexation is ongoing (or so it seems on the dev tool…). However, I can’t seem to get the reindex task as a response to my requests. I have tried to do so with several ways, by using the TasksRequest/TasksResponse object, as well as using a RestClient to reach the url that I use in the devtool on opensearch dashboard (/_tasks and /_cat/tasks amongst other things).
I get my other tasks as a response,
Would you happen to know why I can’t get the reindex tasks ? (I run my unit tests using test containers, and I’ve tried adding up to 100 000 documents so that the task is long enough to be detected).
Thanks in advance for any explanation you might think of regarding this issue, and don’t hesitate to ask me if you need more information from my side :slight_smile:

Relevant Logs or Screenshots:

Response I get from opensearch dashboard, while reindexation is still ongoing:

Response I get from my test containers, while reindexation is still ongoing:

When calling the reindex API, you can set the query parameter wait_for_completion to false, the API will return a taskId immediately and the reindex operation will execute asynchronously, then you can use tasks API to track the progress of the operation by the parent taskId returned, something like this:

1. POST _reindex?wait_for_completion=false
2. GET _tasks/{taskId}

Thanks for your answer, after testing it on our preproduction environment yesterday, my method worked properly but not on test containers, with the taskId it’s WAYYYY easier and cleaner :slight_smile:

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