ES7 JavaApi 使用ik分词器

//  一 、新建索引时设置索引全部默认分词器为ik

CreateIndexRequest request = new CreateIndexRequest("索引名");
request.settings(Settings.builder().put("index.number_of_shards", 3) // 分片数
.put("index.number_of_replicas", 2) // 副本数
.put("analysis.analyzer.default.tokenizer", "ik_max_word") // 设置默认分词器
);

// 客户端执行请求,请求后获得响应
CreateIndexResponse response = esUtils.client().indices().create(request, RequestOptions.DEFAULT);
System.out.println(response);

 

// 二、设置某个字段使用ik分词器

CreateIndexRequest request = new CreateIndexRequest("索引名");

XContentBuilder builder = XContentFactory.jsonBuilder();

builder.startObject().startObject("properties")
.startObject("name").field("type","text").field("analyzer","ik_max_word").endObject()
.startObject("phone").field("type","text").field("analyzer","ik_max_word").endObject()
.startObject("test").field("type","text").field("analyzer","ik_max_word").endObject()
.startObject("address").field("type","text").field("analyzer","ik_max_word").endObject()
.endObject()
.endObject();
request.mapping(builder);

//2客户端执行请求,请求后获得响应
CreateIndexResponse response = esUtils.client().indices().create(request, RequestOptions.DEFAULT);
System.out.println(response);

上一篇:C语言面试题分类->指针


下一篇:CF1601E Phys Ed Online