The Elasticsearch module provides integration with the spring-data-elasticsearch library.
Add the following dependencies to your Maven project :
<dependency>
<groupId>io.github.udev-tn</groupId>
<artifactId>querydsl-elasticsearch</artifactId>
<version>${querydsl-elasticsearch.version}</version>
</dependency>Code generation is currently accessible for Elasticsearch, pending approval of the pull request in the querydsl-apt repository.
Querying with Querydsl Elasticsearch is as simple as this:
QTweet qTweet = QTweet.tweet;
ElasticsearchOperations operations; // a bean initialized by spring-data-elasticsearch
ElasticsearchQuery query = new ElasticsearchQuery(operations, Tweet.class);
List<Document> documents = query
.where(qTweet.views.between(2, 7).and(qTweet.title.startsWith("Breaking")))
.limit(3)
.offset(2)
.fetch();- To use the querydsl elasticsearch repository with synchronized operations, you will need to inject
the ElasticsearchQuerydslRepositoryFactoryBean.class
into repositoryFactoryBeanClass within the
@EnableElasticsearchRepositoriesannotation of your application. This allows for seamless integration and efficient querying within your Elasticsearch environment.
@SpringBootApplication
@EnableReactiveElasticsearchRepositories(repositoryFactoryBeanClass = io.udev.querydsl.elasticsearch.repository.support.ElasticsearchQuerydslRepositoryFactoryBean.class)
class ElasticsearchWithQuerydslSyncApplication {
// application definition
}- To use the querydsl elasticsearch repository with reactive operations, you will need to inject
the ReactiveElasticsearchQuerydslRepositoryFactoryBean.class
into repositoryFactoryBeanClass within the
@EnableElasticsearchRepositoriesannotation of your application.
@SpringBootApplication
@EnableReactiveElasticsearchRepositories(repositoryFactoryBeanClass = io.udev.querydsl.elasticsearch.repository.support.ReactiveElasticsearchQuerydslRepositoryFactoryBean.class)
class ReactiveElasticsearchWithQuerydslApplication {
// application definition
}Following that, you have the opportunity to expand your repositories by using the elasticsearch querydsl contacts.
- For synchronized instances: ElasticsearchExecutor.java
- For reactive instances: ReactiveElasticsearchExecutor.java
You don't need to build from source to use Querydsl-elasticsearch (binaries available on mvnrepository.com), but if you want to test the most recent version, you can easily build querydsl-elasticsearch with the maven cli.
You need JDK 17 or above to build the main branch.
mvn clean install