Skip to content

udev-tn/querydsl-elasticsearch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Querydsl Elasticsearch

The Elasticsearch module provides integration with the spring-data-elasticsearch library.

Maven integration

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>

Creating the query types

Code generation is currently accessible for Elasticsearch, pending approval of the pull request in the querydsl-apt repository.

Querying

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();

Enable Spring Data Repositories

  • To use the querydsl elasticsearch repository with synchronized operations, you will need to inject the ElasticsearchQuerydslRepositoryFactoryBean.class into repositoryFactoryBeanClass within the @EnableElasticsearchRepositories annotation 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
}
@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.

Building from Source

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

About

Elasticsearch support for Querydsl.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages