• 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了解。

      

  • 相关阅读:
    【安卓】安卓res文件夹下的资源文件与R.java文件里面类的对应关系
    超简单,安卓模拟器手动root
    C++成员初始化顺序
    C++,当类名和对象名称相同时会发生什么?
    C++ 修饰名的格式探究
    总结一下classpath
    卡鲁斯卡尔
    ST表
    P2672跳石头
    2019奥赛考前刷题计划
  • 原文地址:https://www.cnblogs.com/dibinbin/p/12091850.html
Copyright © 2020-2023  润新知