Skip to content

Instantly share code, notes, and snippets.

@bluething
Created September 22, 2017 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bluething/3cdee2544fbea6939b4effb068a446e6 to your computer and use it in GitHub Desktop.
Save bluething/3cdee2544fbea6939b4effb068a446e6 to your computer and use it in GitHub Desktop.
<?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:context="http://www.springframework.org/schema/context"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<!-- Spring Data ElasticSearch -->
<elasticsearch:node-client id="client"
cluster-name="${elastic.client.cluster-name}" http-enabled="false"
local="false" path-home="target/test-home-dir"
path-configuration="node-client-configuration.yml" />
<elasticsearch:repositories base-package="com.pegipegi.api.repository" />
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client" />
</bean>
<!-- 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="${elastic.client.cluster-node}" />
</bean>
<bean id="maxTotalConnection" class="java.lang.Integer">
<constructor-arg index="0" value="${elastic.maxTotalConnection}" />
</bean>
<bean id="jestClientConfigBuilderMaxConn"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="jestClientConfigBuilder" />
<property name="targetMethod" value="maxTotalConnection" />
<property name="arguments" ref="maxTotalConnection" />
</bean>
<bean id="defaultMaxTotalConnectionPerRoute" class="java.lang.Integer">
<constructor-arg index="0"
value="${elastic.defaultMaxTotalConnectionPerRoute}" />
</bean>
<bean id="jestClientConfigBuilderDefaultMaxConnPerRoute"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="jestClientConfigBuilder" />
<property name="targetMethod" value="defaultMaxTotalConnectionPerRoute" />
<property name="arguments" ref="defaultMaxTotalConnectionPerRoute" />
</bean>
<bean id="multiThreadedConfig" class="java.lang.Boolean">
<constructor-arg index="0" value="true" />
</bean>
<bean id="jestClientConfigMultiThreaded"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="jestClientConfigBuilder" />
<property name="targetMethod" value="multiThreaded" />
<property name="arguments" ref="multiThreadedConfig" />
</bean>
<bean id="maxIdleConnectionTimeConfigMilis" class="java.lang.Long">
<constructor-arg index="0" value="${elastic.maxConnectionIdleTime}" />
</bean>
<bean id="jestMaxIdleConnectionTime"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="jestClientConfigBuilder" />
<property name="targetMethod" value="maxConnectionIdleTime" />
<property name="arguments">
<list>
<ref bean="maxIdleConnectionTimeConfigMilis" />
<util:constant static-field="java.util.concurrent.TimeUnit.MILLISECONDS"/>
</list>
</property>
</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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment