Hello,
during the process of migrating our code base from the Java High Level REST Client to the Java API Client, we are hitting an issue when trying to retrieve fields mappings.
When running the following code (with an Elasticsearch 7.17.3 server running, and using version 7.16.3 of the Java API Client):
RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build();
ObjectMapper om = new ObjectMapper();
JsonpMapper mapper = new JacksonJsonpMapper(om);
ElasticsearchTransport transport = new RestClientTransport(restClient, mapper);
ElasticsearchClient client = new ElasticsearchClient(transport);
GetFieldMappingRequest gfmRequest = new GetFieldMappingRequest.Builder()
.index("*")
.fields("*")
.build();
GetFieldMappingResponse gfmResponse = client.indices().getFieldMapping(gfmRequest);
the following exception is thrown:
Exception in thread "main" co.elastic.clients.json.UnexpectedJsonEventException: Unexpected JSON event 'KEY_NAME' instead of 'END_OBJECT'
at co.elastic.clients.json.JsonpUtils.expectEvent(JsonpUtils.java:57)
at co.elastic.clients.json.JsonpUtils.expectNextEvent(JsonpUtils.java:51)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:197)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:137)
at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75)
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.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:72)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:176)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:137)
at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75)
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.endpoints.DictionaryResponse.lambda$setupDictionaryResponseDeserializer$0(DictionaryResponse.java:148)
at co.elastic.clients.json.ObjectDeserializer.parseUnknownField(ObjectDeserializer.java:205)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:174)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:137)
at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:75)
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:291)
at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:144)
at co.elastic.clients.elasticsearch.indices.ElasticsearchIndicesClient.getFieldMapping(ElasticsearchIndicesClient.java:1062)
When calling the REST API directly (GET http://localhost:9200//_mapping/field/), it returns valid JSON with an HTTP 200 status.
Is it an issue with the Java API Client or an issue with our code ? How can we fix this ?
Thanks for your help.