zoukankan      html  css  js  c++  java
  • spring boot与ElasticSearch的集成

    本文主要介绍Spring boot与ElasticSearch的集成,因为Spring boot的教程以及ElasticSearch的学习其他博客可能更优秀,所以建议再看这篇文章前先学习学习一下Spring boot与ElasticSearch,这篇博客更着重实战

    1.首先要引入依赖包

    2.配置参数

         elasticsearch.cluster.name=集群名字

         elasticsearch.host=127.0.0.1

         elasticsearch.port=9300

    3.配置类编写   

    @Configuration
    public class ElasticSearchConfig {
         @Value("${elasticsearch.host}")
         private String esHost;

        @Value("${elasticsearch.port}")
         private int esPort;

        @Value("${elasticsearch.cluster.name}")
        private String esName;

         @Bean
        public TransportClient esClient() throws UnknownHostException {
             Settings settings = Settings.builder().put("cluster.name", this.esName)
            // .put("cluster.name", "elasticsearch")
            .put("client.transport.sniff", true)
            .build();

            InetSocketTransportAddress master = new InetSocketTransportAddress(InetAddress.getByName(esHost), esPort
            // InetAddress.getByName("10.99.207.76"), 8999
           );

            TransportClient client = new PreBuiltTransportClient(settings)
           .addTransportAddress(master);

           return client;
         }
    }

    4,注入其相关配置信息

        @Autowired
               private TransportClient esClient;

    常用方法:prepareSearch,prepareIndex,prepareUpdate等,请查询Api了解。

      

  • 相关阅读:
    C#.NET中现在用的SqlHelper操作方法集合【收藏版】
    SQLHelper.cs的经典代码收集
    ASP.NET数据格式的Format DataFormatString
    asp.net操作 httpcookie
    项目开发中我所用到的SQL收集
    GridView的dataformatstring设置
    jQuery事件处理: 别再乱用“return false”了
    非常不错的空白占位符“    ”
    Hello World
    VSFlexGrid 控件属性方法一览
  • 原文地址:https://www.cnblogs.com/dibinbin/p/12091850.html
Copyright © 2011-2022 走看看