Migration from HighRestLevelCLient to ElasticSearchClient

Good morning,
We are planning to upgrade to springboot3.0 and we are heavily using the deprecated client named HighRestLevelClient which is removed in springboot3 and replaced with the new java api client named ElasticSearchClient. however, we are runinng into some troubles because there is a big lag between the two clients.
For example, our application creates indexes along with ilm policies (index lifecycle management) in this way

private static void createIlmPolicy(RestHighLevelClient elasticClient, ElasticProperties elasticProperties) throws IOException {

        if (elasticProperties.getIndexPolicies() != null) {
            IndexLifecycleNamedXContentProvider indexLifecycleNamedXContentProvider = new IndexLifecycleNamedXContentProvider();
            NamedXContentRegistry registry = new NamedXContentRegistry(indexLifecycleNamedXContentProvider.getNamedXContentParsers());

            for (IndexPolicy p : elasticProperties.getIndexPolicies()) {

                elasticClient.indexLifecycle().putLifecyclePolicy(
                        new PutLifecyclePolicyRequest(
                                LifecyclePolicy.parse(
                                        JsonXContent.jsonXContent.createParser(registry, LoggingDeprecationHandler.INSTANCE, jsonMapper.writeValueAsString(p.getPolicy())),
                                        p.getName()
                                )
                        ),
                        RequestOptions.DEFAULT
                );
            }
        }
    }

How can we do this with the new java client, knowing that there is nomore indexLifecycle() ,putLifecyclePolicy() methods availble in the java api client?
Thanks in advance

This should look like this:

private static void createIlmPolicy(ElasticsearchClient elasticClient, ElasticProperties elasticProperties) throws IOException {
    if (elasticProperties.getIndexPolicies() != null) {

        for (IndexPolicy p : elasticProperties.getIndexPolicies()) {

            elasticClient.ilm().putLifecycle(l -> l
                .name(p.getName())
                .withJson(new StringReader(p.getPolicy()))
            );
        }
    }
}
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.