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;
}

关键点:

 源码关键点:

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值