栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

elasticsearch7.2 mapping设置分词器

elasticsearch7.2 mapping设置分词器

java程序 设置elasticsearch7.2 mapping分词器



@Override
public void createIndex(String belonging) throws IOException {
    if (belonging!=null&&!"".equals(belonging)) {
        if (!existsIndex("knowledge"+belonging)) {
            CreateIndexRequest request = new CreateIndexRequest("knowledge"+belonging);
            request.settings(Settings.builder()
                    .put("index.number_of_shards", 3)
                    .put("index.number_of_replicas", 2)
            );
            toBulidMapping(request);
            //request.mapping(String.valueOf(mapping));
            CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT);
            System.out.println(response.toString());
            log.info("索引创建结查:" + response.isAcknowledged());
        } else {
            log.warn("索引:{},已经存在,不能再创建。", "knowledge"+belonging);
        }
    }
}

private static void toBulidMapping(CreateIndexRequest request){
    String[] source=new String[]{
            "id", "type=integer",
            "title", "type=text,analyzer=ik_max_word",
            "summary", "type=text,analyzer=ik_max_word",
            "source", "type=text",
            "author", "type=text,analyzer=ik_max_word",
            "belonging", "type=text",
            "documentId", "type=integer",
            "status", "type=keyword",
            "createby", "type=integer",
            "createtime", "type=date",
            "approveby", "type=integer",
            "approvetime", "type=date",
            "topping", "type=keyword",
            "toppingtime", "type=date",
            "textStr","type=text,analyzer=ik_max_word"
    };

    request.mapping("_doc",source);

}
public boolean existsIndex(String index) throws IOException {
    GetIndexRequest request = new GetIndexRequest();
    request.indices(index);
    log.info("source:" + request.toString());
    boolean exists = client.indices().exists(request, RequestOptions.DEFAULT);
    log.debug("existsIndex: " + exists);
    return exists;
}

关键点:

 源码关键点:

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/747763.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号