Spring Data implementation for ElasticSearch based on Jest Rest client
Useful to use Spring Data with ElasticSearch cluster accessible only by HTTP ( for example on AWS).
spring data jest | spring boot | spring data elasticsearch | jest | elasticsearch |
---|---|---|---|---|
3.3.4.RELEASE | 2.2.1 | 3.2.1.RELEASE | 6.3.1 | 6.8.4 |
3.2.5.RELEASE | 2.1.2 | 3.1.3.RELEASE | 6.3.1 | 6.4.3 |
3.1.5.RELEASE | 2.0.5 | 3.0.10.RELEASE | 5.3.4 | 5.5.0 |
3.0.0.RELEASE | 2.0.0.M4 | 3.0.0.RELEASE | 5.3.2 | 5.5.0 |
2.3.1.RELEASE | 1.5.x | 2.1.0.RELEASE | 2.0.4 | 2.4.4 |
2.2.0.RELEASE | >= 1.4.3 | 2.0.6.RELEASE | 2.0.4 | 2.4.3 |
2.1.4.RELEASE | < 1.4.3 | 2.0.5.RELEASE | 2.0.3 | 2.2.0 |
1.0.2.RELEASE | 1.3.x | 1.3.4.RELEASE | 1.0.3 | 1.5.2 |
Add the Maven dependency:
<dependency>
<groupId>com.github.vanroy</groupId>
<artifactId>spring-boot-starter-data-jest</artifactId>
<version>3.3.4.RELEASE</version>
</dependency>
<!-- Only required for start local ES node -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
For specific case of AWS ES Domain (with Request Signing) add this dependency:
<dependency>
<groupId>vc.inreach.aws</groupId>
<artifactId>aws-signing-request-interceptor</artifactId>
<version>0.0.21</version>
</dependency>
@SpringBootApplication(exclude = {ElasticsearchAutoConfiguration.class, ElasticsearchDataAutoConfiguration.class})
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
spring:
data:
jest:
uri: http://localhost:9200
# Useful only for AWS request signing ( not required on EC2 instance, it's auto-discovered )
aws-region: eu-west-1
Add the Maven dependency:
<dependency>
<groupId>com.github.vanroy</groupId>
<artifactId>spring-data-jest</artifactId>
<version>3.3.4.RELEASE</version>
</dependency>
<!-- Only required for start local / embedded ES node -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
You can set up repository scanning via xml configuration, which will happily create your repositories.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd">
<!-- Elastic search test node -->
<elasticsearch:node-client id="client" local="true" cluster-name="#{T(java.util.UUID).randomUUID().toString()}"
http-enabled="true" path-data="target/elasticsearchTestData" path-home="src/test/resources/test-home-dir"
path-configuration="node-client-configuration.yml"/>
<!-- ElasticSearch Jest Client -->
<bean id="jestClient" factory-bean="jestClientFactory" factory-method="getObject" destroy-method="close" />
<bean id="jestClientConfigBuilder" class="io.searchbox.client.config.HttpClientConfig.Builder">
<constructor-arg type="java.lang.String" value="http://localhost:9200"/>
</bean>
<bean id="jestClientConfig" factory-bean="jestClientConfigBuilder" factory-method="build"/>
<bean id="jestClientFactory" class="io.searchbox.client.JestClientFactory">
<property name="httpClientConfig" ref="jestClientConfig"/>
</bean>
<!-- Elasticsearch Jest Template -->
<bean id="jestElasticsearchTemplate" class="com.github.vanroy.springdata.jest.JestElasticsearchTemplate">
<constructor-arg ref="jestClient"/>
</bean>
</beans>
Sample with Spring Boot and embedded Elasticsearch :
https://github.com/VanRoy/spring-data-jest/tree/master/spring-boot-sample-data-jest
Sample with Spring Boot and Elasticsearch on AWS (managed) :
https://github.com/VanRoy/spring-data-jest/tree/master/spring-boot-sample-data-jest-aws
All plugins located in org.elasticsearch.plugin
are loaded by default.
All plugins located in packages specified in property spring.data.jest.pluginPackages
are also loaded.
In pom.xml, add plugin dependency :
<dependency>
<groupId>org.codelibs.elasticsearch.module</groupId>
<artifactId>lang-expression</artifactId>
<version>...</version>
</dependency>
In application.yml, add following :
spring:
data:
jest:
pluginPackages: org.elasticsearch.script.expression
JetBrains supports our open source project by sponsoring a All Products Packs within their Free Open Source License program.