Search code examples
elasticsearchspring-data-elasticsearch

can I use old spring-data-elasticsearch to connect to new elasticsearch?


Currently we are on spring-data-elasticsearch 3.2.6 + elasticsearch 6.8. We are moving to new elasticsearch 7.x. Do I have to update spring-data-elasticsearch to 4.x? We only use ElasticsearchRepository in spring-data-elasticsearch. And we don't need to use any new feature in elasticsearch 7.x.

If we are moving to elasticsearch 8.x in the future, do I need update spring-data-elasticsearch ?

Update:

What Elasticsearch client does Spring-Data-Elasticsearch use under the hood?

All methods in the `ElasticsearchRepository` are deprecated. What should do I use?

I found some discussions in above threads. Here is my summary.

  1. Operations with Templates:

ElasticsearchTemplate implements ElasticSearchOperation. It uses TransportClient(which is deprecated in ES 7 and has been removed in ES8)

ElasticsearchRestTemplate implements ElasticSearchOperation. It uses high level client(which is deprecated in ES 7.16.0. It will be removed in future. @Deprecated(since = "7.16.0", forRemoval = true) )

ReactiveElasticsearchTemplate implements ReactiveElasticsearchOperations. It uses Reactive Client.

  1. Repository

ElasticsearchRepository uses TransportClient as default. All methods in the ElasticsearchRepository are deprecated now.

Reactive Elasticsearch repository builds on ReactiveElasticsearchOperations.


Due to underlying TransportClient or HigLevelRestClient has been deprecated, can I conclude that the correct way is to use Reactive Client(ReactiveElasticsearchTemplate or Reactive Elasticsearch repository) ?


Solution

  • The new Elasticsearch would be 8.

    Val already put the link to the compatibility matrix in his comment.

    Version 3.2.6 is pretty outdated (March 25 2020) and out of support since October 2020.

    The first thing you can try is to see if your application works with a 7 cluster - although I doubt that, I can't tell you exactly what had changed in the API, but there was quite some stuff.

    What you should not do is putting newer Elasticsearch libraries on the classpath than the ones that Spring Data Elasticsearch was built with, this will in most cases make problems.

    But I'd recommend to upgrade your application anyway and keep it regularly up to date.

    As for future upgrade to version 8: It is possible to send a compatibility header in your requests (this can be done in Spring Data Elasticsearch 4) and the Elasticsearch cluster should respond in a format that is compatible with a client expecting version 7. I wrote should, because it does not conform to this in every case - I reported one case that is fixed now. But I wouldn't rely on that.

    Again, please update your application and keep it up to date, not only because of Spring Data Elasticsearch, but also because these updates always include bug and/or security fixes.