Elasticsearch - Java API Client vs Spring Data Elasticsearch

Elasticsearch Java API Client vs Spring Data Elasticsearch

Although the Elasticsearch Client can be used directly to work with the cluster, applications using Spring Data Elasticsearch normally use the higher level abstractions of Elasticsearch Operations and Elasticsearch Repositories.

There are pros and cons to this approach.

We get nice benefits from Spring like repositories, reactor integration, pagination. However not all features are supported, so you will have to use elasticsearch java API directly in some of the use cases. Spring Data Elastic Search can sometimes seem like a worthless layer of abstraction.

If you want to roll your own, ES supports OpenAPI, you could download the spec and generate a Java client of your choosing as well with OpenAPI generator: https://openapi-generator.tech/

Some teams choose Java API client over Spring Data Elastichsearch because Spring data does not support the latest versions of ES. We see errors like Spring Boot 3.1 cannot use Elasticsearch Client 8.9.0. Some teams are completely satisfied with API client. The only thing they would lack is pagination. And if they can come up with their own paginator, they should be ok.

With Elastic Java Client, we can be agnostic for the framework in a future if you decide to change it (from Spring to something else).


Links to this note