elastic/elasticsearch-java

JsonpMapperFeatures#SERIALIZE_TYPED_KEYS still requires typed keys for aggregation

hanusto opened this issue · 1 comments

Java API client version

8.7.1

Java version

17

Elasticsearch Version

8.9.0

Problem description

Hi,

I am using Spring Boot 3.1.2, actually we are migration a stack from SB 2.7 to 3.1.2 SB.

We used aggregations without typed keys. Probably in previous version of ES 7.17.3 default behaviour of old ES client to not enforce of using typed keys but current client (8.7) has opposite default. We are facing issue during deserialization of response (search template, transport.performRequestAsync(request,SearchTemplateRequest.createSearchTemplateEndpoint(this.getDeserializer(tDocumentClass)), transportOptions))).

I would like to switch it (doc) so I create this configuartion for SB:

    @Configuration
    static class JacksonJsonpMapperConfiguration {
        // https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html#return-agg-type
        // https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/serialize-without-typed-keys.html
        @Bean
        JsonpMapper jacksonJsonpMapper() {
            return new JacksonJsonpMapper().withAttribute(JsonpMapperFeatures.SERIALIZE_TYPED_KEYS, false);
        }
    }

During debugging I see that JsonpDeserializer is using JsonpMapper (JacksonJsonpMapper) with co.elastic.clients.json.JsonpMapperFeatures:SERIALIZE_TYPED_KEYS -> false, so I am expecting that this configuration helps to parse search response without typed keys:

image

But I am getting following error:

 Error deserializing co.elastic.clients.elasticsearch._types.aggregations.CompositeBucket: Property name 'hits' is not in the 'type#name' format. Make sure the request has 'typed_keys' set. (JSON path: aggregations.buckets[1].hits) (line no=64, column no=20, offset=-1)
	at co.elastic.clients.json.ExternallyTaggedUnion$TypedKeysDeserializer.deserializeEntry(ExternallyTaggedUnion.java:123) ~[elasticsearch-java-8.7.1.jar:na]

So question is how can deserialize Elasticsearch response without typed keys in aggregation? Where is the logic whether the co.elastic.clients.json.ExternallyTaggedUnion will be used for deserialization without typed key or not?