elastic / elasticsearch-java

Official Elasticsearch Java Client
Apache License 2.0
397 stars 228 forks source link

Update from 8.13.4 to 8.14.1 break the dynamic template creation #841

Closed TakiuGit closed 2 weeks ago

TakiuGit commented 3 weeks ago

Java API client version

8.14.1

Java version

openjdk 11.0.21 2023-10-17 LTS

Elasticsearch Version

8.4.3

Problem description

Upgrading the driver from 8.13.4 to 8.14.1 I've come up with the following issue

Pushing to an ES server v8.4.3 introduce brackets in the "path_match" field in "dynamic_templates". ex : from "titles.*" to "[titles.*]" This is an actual breaking change as the template does not match anymore with the targeted fields names

Here is a minimal example to reproduce:

 public static void main(String[] args) throws IOException {
        RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build();
        ElasticsearchClient client = new ElasticsearchClient(
                    new RestClientTransport(restClient, new JacksonJsonpMapper()));

        Map<String, DynamicTemplate> value = Map.of("titles",
            new DynamicTemplate.Builder().pathMatch("titles.*")
                .mapping(new Property.Builder().text(new TextProperty.Builder().build()).build())
                .build());

        CreateIndexRequest indexRequest = new CreateIndexRequest.Builder().index("test_index")
            .mappings(new TypeMapping.Builder().dynamicTemplates(value).build())
            .build();
        client.indices().create(indexRequest);
    }

This is not reproducible with the server version 8.13.4, I've not tested with other versions.

l-trotta commented 2 weeks ago

Hello! The issue here is the server version 8.4.3, which doesn't allow multiple values for the dynamic templates pattern matching, a feature added around version 8.9 of the server. The clients are forward compatible only, meaning that we cannot guarantee compatibility with older versions of the server; in this particular case the problem lies with how the client simplifies parameters that can accept both a single string or arrays to just arrays. Updating the server to a more recent version should solve this.

TakiuGit commented 2 weeks ago

Hi @l-trotta, sorry for the trouble and thank's for your fast answer, I was not aware of the forward compatibility policy :+1: