opensearch-project / opensearch-java

Java Client for OpenSearch
Apache License 2.0
126 stars 190 forks source link

[BUG] Listing tasks without grouping fails with: Unexpected JSON event 'START_ARRAY' instead of '[START_OBJECT]' #1326

Open fs-chris opened 1 day ago

fs-chris commented 1 day ago

What is the bug?

When trying to get tasks as list with group_by=none option the response cannot be parsed. The following exception is thrown

UnexpectedJsonEventException: Unexpected JSON event 'START_ARRAY' instead of '[START_OBJECT]'
    at deployment.njams-6.1.0-SNAPSHOT.war//org.opensearch.client.json.JsonpUtils.ensureAccepts(JsonpUtils.java:116)
    at deployment.njams-6.1.0-SNAPSHOT.war//org.opensearch.client.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:86)
    at deployment.njams-6.1.0-SNAPSHOT.war//org.opensearch.client.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:81)
    at deployment.njams-6.1.0-SNAPSHOT.war//org.opensearch.client.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:185)
    at deployment.njams-6.1.0-SNAPSHOT.war//org.opensearch.client.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:146)
    at deployment.njams-6.1.0-SNAPSHOT.war//org.opensearch.client.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:87)
    at deployment.njams-6.1.0-SNAPSHOT.war//org.opensearch.client.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:91)
    at deployment.njams-6.1.0-SNAPSHOT.war//org.opensearch.client.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:55)
    at deployment.njams-6.1.0-SNAPSHOT.war//org.opensearch.client.transport.rest_client.RestClientTransport.decodeResponse(RestClientTransport.java:360)
    at deployment.njams-6.1.0-SNAPSHOT.war//org.opensearch.client.transport.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:326)
    at deployment.njams-6.1.0-SNAPSHOT.war//org.opensearch.client.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:148)
    at deployment.njams-6.1.0-SNAPSHOT.war//org.opensearch.client.opensearch.tasks.OpenSearchTasksClient.list(OpenSearchTasksClient.java:153)
    at deployment.njams-6.1.0-SNAPSHOT.war//org.opensearch.client.opensearch.tasks.OpenSearchTasksClient.list(OpenSearchTasksClient.java:166)

A sample request/response looks like

GET _tasks?group_by=none
{ 
  "tasks": [ 
    { 
      "node": "a8R07eoVQxqZhrN8WWZBUQ",
      "id": 6616,
      "type": "transport",
      "action": "cluster:monitor/tasks/lists",
      "start_time_in_millis": 1732530485437,
      "running_time_in_nanos": 337735,
      "cancellable": false,
      "cancelled": false,
      "headers": { 

      }
    },
    { 
      "node": "a8R07eoVQxqZhrN8WWZBUQ",
      "id": 6617,
      "type": "direct",
      "action": "cluster:monitor/tasks/lists[n]",
      "start_time_in_millis": 1732530485437,
      "running_time_in_nanos": 114967,
      "cancellable": false,
      "cancelled": false,
      "parent_task_id": "a8R07eoVQxqZhrN8WWZBUQ:6616",
      "headers": { 

      }
    }
  ]
}

How can one reproduce the bug?

Build and execute a request like this: client.tasks().list(t -> t.groupBy(GroupBy.None))

What is the expected behavior?

The response should be parsed into a ListResponse

What is your host/environment?

Java Client: 2.18.0 OpenSearch server: 2.18.0 (Docker)

Do you have any screenshots?

n/a

Do you have any additional context?

n/a

Xtansia commented 6 hours ago

This issue has already been fixed for the future 3.0.0 release, but it is not directly backwards compatible so hasn't been backported for 2.x yet.