• 自定义初始化ES实体类


    /*
    package com.dict.business.esinit;
    
    import com.dict.business.domain.ESHomeSearch;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.CommandLineRunner;
    import org.springframework.core.annotation.Order;
    import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
    import org.springframework.stereotype.Component;
    
    @Component
    @Order(value = 0)
    @Slf4j
    public class ESHomeSearchInitIndex implements CommandLineRunner {
    
        @Autowired
        ElasticsearchRestTemplate elasticsearchRestTemplate;
    
        */
    /**
         * 项目启动的时候,如果elasticsearch已经存有索引,则不做任何操作
         * 如果没有索引,则新建索引
         *
         * @param args
         * @throws Exception
         *//*
    
        @Override
        public void run(String... args) throws Exception {
            boolean indexExists = elasticsearchRestTemplate.indexExists(ESHomeSearch.class);
            if (indexExists) {
                log.warn("存在索引");
            } else {
                log.warn("索引不存在。。。");
                try {
                    boolean index = elasticsearchRestTemplate.createIndex(ESHomeSearch.class, EsData.DEFAULT_SETTING);
                    boolean putMapping = elasticsearchRestTemplate.putMapping(ESHomeSearch.class);
                    if (index && putMapping) {
                        log.info("索引创建成功。。。");
                    } else {
                        log.warn("索引创建失败。。。");
                    }
                } catch (Exception e) {
                    log.error("error: {}", e.getLocalizedMessage());
                }
            }
        }
    }
    */
    View Code

    ES  setting

    package com.dict.business.esinit;
    
    public class EsData {
    
        public static final String DEFAULT_SETTING = "{\n" +
                "        \"analysis\" : {\n" +
                "            \"analyzer\" : {\n" +
                "                \"tsconvert\" : {\n" +
                "                    \"tokenizer\" : \"tsconvert\"\n" +
                "                    }\n" +
                "            },\n" +
                "            \"tokenizer\" : {\n" +
                "                \"tsconvert\" : {\n" +
                "                    \"type\" : \"stconvert\",\n" +
                "                    \"delimiter\" : \"#\",\n" +
                "                    \"keep_both\" : false,\n" +
                "                    \"convert_type\" : \"t2s\"\n" +
                "                }\n" +
                "            },   \n" +
                "             \"filter\": {\n" +
                "               \"tsconvert\" : {\n" +
                "                     \"type\" : \"stconvert\",\n" +
                "                     \"delimiter\" : \"#\",\n" +
                "                     \"keep_both\" : false,\n" +
                "                     \"convert_type\" : \"t2s\"\n" +
                "                 }\n" +
                "             },\n" +
                "            \"char_filter\" : {\n" +
                "                \"tsconvert\" : {\n" +
                "                    \"type\" : \"stconvert\",\n" +
                "                    \"convert_type\" : \"t2s\"\n" +
                "                }\n" +
                "            }\n" +
                "        }\n" +
                "    }";
    
    }
    View Code
  • 相关阅读:
    gdb高级技巧
    Fira Code字体安装与配置
    回归
    【Luogu】P2292 [HNOI2004]L语言 题解
    浅谈Linux桌面(发行版及桌面环境)
    剑指offer-和为S的连续正数序列-知识迁移能力-python
    剑指offer-数组中只出现一次的数字-数组-python
    剑指offer-数字在排序数组中出现的次数-数组-python
    剑指offer-数组中的逆序对-数组-python
    剑指offer-丑数-穷举-python
  • 原文地址:https://www.cnblogs.com/bulrush/p/16107987.html
Copyright © 2020-2023  润新知