Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use Specifications in ElasticsearchRepository?

I've implemented the Specification pattern for filtering some of my JpaRepositories. After I have implemented a Specification, I can use it with a JpaRepository like this: Page<Entity> page = entityJpaRepository.findAll(entitySpecification, pageable)

Is there a feature, or planned feature, for supporting Specifications in ElasticsearchRepository?

like image 821
geraldhumphries Avatar asked Dec 02 '15 20:12

geraldhumphries


People also ask

Why ElasticsearchTemplate is deprecated?

The ElasticsearchTemplate class is deprecated as it uses the TransportClient to access Elasticsearch, which itself is deprecated since Elasticsearch version 7. + Users should switch to ElasticsearchRestTemplate or ReactiveElasticsearchTemplate .

Does Elasticsearch use spring?

Spring Data for Elasticsearch is part of the umbrella Spring Data project which aims to provide a familiar and consistent Spring-based programming model for for new datastores while retaining store-specific features and capabilities.

Is Elasticsearch reactive?

Spring Data Elasticsearch comes with three interfaces that supports reactive operations: ReactiveRepository , ReactiveCrudRepository that adds save/update operations, and ReactiveSortingRepository offering some methods with sorting.

What is Elasticsearchrepository?

Elasticsearch Repository It will detect issues and improve your Elasticsearch performance by analyzing your shard sizes, threadpools, memory, snapshots, disk watermarks and more.


1 Answers

I understand your pain however the thing is that Specification interface belongs to the JPA API that currently none of the Elastic Search Spring Data repositories implement and I don't think they will.

If you really want to use them you should rather migrate from ElasticsearchRepository coming from spring-data-elasticsearch into JPA-based repositories.

Did not try to use JPA together with ElasticSearch myself but noticed that some people does it, check out this link:

https://programmertoday.com/spring-boot-elastic-search-with-spring-data-jpa/

like image 91
Aleksander Lech Avatar answered Sep 21 '22 11:09

Aleksander Lech