2014-01-26 109 views
0

我使用弹性搜索中,我通过弹簧工具覆盖弹簧弹性的数据搜索群集节点配置

弹簧数据弹性搜索

传达给后端ES簇我的项目活动

以下是webapp的spring-repository描述。

<?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/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> 

    <elasticsearch:transport-client id="client" cluster-nodes="localhost:9300" /> 

    <bean name="elasticsearchTemplate" 
     class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate"> 
     <constructor-arg name="client" ref="client" /> 
    </bean> 

    <elasticsearch:repositories 
     base-package="com.customer.repositories" /> 
</beans> 

在这里,我指定的集群节点配置为集群节点=“本地主机:9300”,它是工作的罚款与我的本地测试。

在生产服务器上,我们有一个全功能的集群设置,主机IP说(192.xx.xx.xx)。所以我的问题是,我们已经在生产服务器的/etc/project/es.yml文件中的yml文件中指定了群集主机。所以我需要调整我的应用程序以从此自定义位置进行群集配置。

由于上面的spring-repository xml由spring容器初始化,所以我们无法覆盖这个行为。有没有办法通过spring-data-elastic-search来实现它?

+0

嘿,spring数据还是弹性搜索专家对于这个问题的任何解决方案? – appu

+0

任何投入春天家伙? – appu

回答

1

最后我解决了我的问题,并在此分享,以便对其他人有用。

更改阳明主意属性文件(es.props)

春天库的描述应该是如下

<?xml version="1.0" encoding="UTF-8"?>co 
<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" 
    xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch 
         http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd 
         http://www.springframework.org/schema/beans 
         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
         http://www.springframework.org/schema/context 
         http://www.springframework.org/schema/context/spring-context-3.1.xsd"> 

    <context:property-placeholder location="file:/etc/project/es.props" /> 

    <elasticsearch:transport-client id="client" cluster-nodes="${es-host}:9300""/> 

    <bean name="elasticsearchTemplate" 
     class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate"> 
     <constructor-arg name="client" ref="client" /> 
    </bean> 

    <elasticsearch:repositories 
     base-package="com.customer.repositories" /> 

</beans> 

其中在3.1+使用弹簧PropertySourcePlaceHolder改性机理。

所以它会查找/etc/project/es.props中的es.host。本地测试人员可以使用-Des.host = custom-cluser -host启动服务器来覆盖此属性。

实际上,Mohsin(Spring-data-elastic-search开发人员)提供了有关此解决方案的提示。谢谢Mohsin。

+0

欢迎您:) –