get task status of forcemerge(wait_for_completion=false) results in error when task completed

Open
#469 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
api, backend

Research direction

Start at ElasticsearchTasksClient.get and the TaskStatus builder, then compare the completed force-merge JSON in the report with the generated response model. Reproduce the wait_for_completion=false flow against Elasticsearch 8.5.0 and verify that the completed response deserializes successfully without a response.batches field.

Written by the indexing model from the issue text.

Description

Java API client version

8.5.2

Java version

1.8

Elasticsearch Version

8.5.0

Problem description

when submit a force merge request with wait_for_completion=false, i got a taskid. and I use task id to query task status

 logger.info("force merge taskId: {}", taskId);
boolean completed = false;
GetTasksResponse tasksResponse = null;
while (!completed) {
    tasksResponse = client.tasks().get(t -> t.taskId(taskId));
    completed = tasksResponse.completed();
    logger.info("force merge task not completed yet");
    try {
        Thread.sleep(2 * 60_000);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}

all seems good when task is still running. but when task finally completes, get task response throws exception

Error deserializing co.elastic.clients.elasticsearch.tasks.GetTasksResponse: co.elastic.clients.util.MissingRequiredPropertyException: Missing required property 'TaskStatus.batches' (JSON path: response) (line no=1, column no=449, offset=-1)
	at co.elastic.clients.json.JsonpMappingException.from0(JsonpMappingException.java:134)
	at co.elastic.clients.json.JsonpMappingException.from(JsonpMappingException.java:121)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:218)
	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:148)
	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:76)
	at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:79)
	at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43)
	at co.elastic.clients.transport.rest_client.RestClientTransport.decodeResponse(RestClientTransport.java:325)
	at co.elastic.clients.transport.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:295)
	at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:148)
	at co.elastic.clients.elasticsearch.tasks.ElasticsearchTasksClient.get(ElasticsearchTasksClient.java:117)
	at co.elastic.clients.elasticsearch.tasks.ElasticsearchTasksClient.get(ElasticsearchTasksClient.java:133)

and the completed response json string should be something like this

{
  "completed": true,
  "task": {
    "node": "xD7kSXXeSXWMURif3cX16w",
    "id": 2180131,
    "type": "transport",
    "action": "indices:admin/forcemerge",
    "description": "Force-merge indices [xxx], maxSegments[1], onlyExpungeDeletes[false], flush[true]",
    "start_time_in_millis": 1671621375383,
    "running_time_in_nanos": 9551767091603,
    "cancellable": false,
    "headers": {}
  },
  "response": {
    "_shards": {
      "total": 6,
      "successful": 6,
      "failed": 0
    }
  }
}

no response.batches exists however batches is force required in TaskStatus of the client code

private TaskStatus(Builder builder) {
    this.batches = ApiTypeHelper.requireNonNull(builder.batches, this, "batches");
    ...
}

i think this a bug not related to https://github.com/elastic/elasticsearch-specification/issues/1767, so i opened this issue

Dominant language
Java
Stars
524
Forks
300
Avg merge
1d 11h
Merged PRs (30d)
16

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from elastic/elasticsearch-java

All issues in elastic/elasticsearch-java

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.