zoukankan      html  css  js  c++  java
  • elasticsearch7.9整合springboot

    1、需要添加依赖

    2、添加配置文件

    package com.example.elasticsearch.shop.configure;
    import org.elasticsearch.client.RestHighLevelClient;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.data.elasticsearch.client.ClientConfiguration;
    import org.springframework.data.elasticsearch.client.RestClients;
    import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
    import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
    
    @Configuration
    class RestClientConfig extends AbstractElasticsearchConfiguration {
        @Bean
        @Override
        public RestHighLevelClient elasticsearchClient() {
            final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
                    .connectedTo("10.138.130.1:30217","10.138.130.1:32002","10.138.130.1:33785")
                    .build();
    
            return RestClients.create(clientConfiguration).rest();
        }
        @Bean(name = { "elasticsearchOperations", "elasticsearchRestTemplate" })
        public ElasticsearchRestTemplate elasticsearchTemplate() {
            return new ElasticsearchRestTemplate(elasticsearchClient());
        }
    }
    

    3、创建索引

    public Boolean createIndex() {
            return elasticsearchRestTemplate.indexOps(ShopEntity.class).create();
        }
    

      

    4、创建mapping

      Document mapping = elasticsearchRestTemplate.indexOps(ShopEntity.class).createMapping(ShopEntity.class);
            boolean brue = elasticsearchRestTemplate.indexOps(ShopEntity.class).putMapping(mapping);
            System.out.println(brue);
            System.out.println(mapping);
    

      

  • 相关阅读:
    序列化实现 深拷贝
    为边框应用图片 border-image
    阴影 box-shadow(二)
    阴影 box-shadow(一)
    css3之圆角效果 border-radius
    文档对象模型(DOM)
    Cookie/Session机制详解
    PHP错误The server encountered an internal error or misconfiguration and was unable to complete your re
    关于js with语句的一些理解
    使用JavaScript+Html创建win8应用(二)
  • 原文地址:https://www.cnblogs.com/liubaihui/p/14009420.html
Copyright © 2011-2022 走看看