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.1.5.RELEASE | 2.0.4 | 3.0.10.RELEASE | 5.3.3 | 5.5.0 |
3.1.0.RELEASE | 2.0.0 | 3.0.5.RELEASE | 5.3.2 | 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.1.5.RELEASE</version>
</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.1.5.RELEASE</version>
</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="shutdownClient" />
<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