美文网首页
Spring集成elasticsearch

Spring集成elasticsearch

作者: 抖抖村的抖抖 | 来源:发表于2017-01-23 17:32 被阅读0次

Artifacts

  • maven
    <dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-elasticsearch</artifactId>
    <version>2.0.2.RELEASE</version>
    </dependency>

Usage

  • XML配置
<?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.xsd
       http://www.springframework.org/schema/data/elasticsearch
       http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd">
    <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>

    <elasticsearch:repositories base-package="com.doudou.demo.repositories"/>
    <!--通过transport方式与ES集群通信,不需要在本地创建节点-->
    <!--client-transport-sniff表示是否进行自动嗅探ES集群中节点-->
    <elasticsearch:transport-client id="es.transport.client"
                                    cluster-nodes="177.177.177.177:9300,177.177.177.176:9300"
                                    cluster-name="DouDouCluster"
                                    client-transport-sniff="false"/>
    <bean name="elasticsearchTemplate" class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
        <constructor-arg name="client" ref="es.transport.client"/>
    </bean>
    <bean id="simpleElasticsearchRepository"
          class="org.springframework.data.elasticsearch.repository.support.SimpleElasticsearchRepository">
        <constructor-arg name="elasticsearchOperations" ref="elasticsearchTemplate"/>
    </bean>
</beans>

相关文章

网友评论

      本文标题:Spring集成elasticsearch

      本文链接:https://www.haomeiwen.com/subject/lhvabttx.html