20181 月21
Elasticsearch 6.1.2 (一)中文分词设置、字符串字段排序设置
if (!esService.isExistsType(cfg.get("es.index.name"), type)) {
//初始化索引表
XContentBuilder mapping = jsonBuilder().startObject()
.startObject(type)
.startObject("_all")//设置IK分词
.field("analyzer", "ik_max_word")
.field("search_analyzer", "ik_max_word")
.field("term_vector", "no")
.field("store", "false")
.endObject()
.startObject("properties")
.startObject("CASNM").field("type", "text").field("analyzer", "ik_max_word").endObject()
.startObject("IQDAT").field("type", "text").field("index", "true").field("fielddata","true").endObject()
.startObject("ANNODAT").field("type", "text").field("index", "true").field("fielddata","true").endObject()
.endObject()
.endObject()
.endObject();
esService.putMapping(cfg.get("es.index.name"), "inquiry", mapping);
}
/**
* @param indexName 索引名
* @param type 数据类型(表名)
* @param mapping mapping对象
*/
public boolean putMapping(String indexName, String type, XContentBuilder mapping) {
PutMappingRequest mappingRequest = Requests.putMappingRequest(indexName).type(type).source(mapping);
PutMappingResponse response = getClient().admin().indices().putMapping(mappingRequest).actionGet();
return response.isAcknowledged();
}
.field(“fielddata”,”true”) //text字段默认不允许排序,是单独设置数据格式
本文地址:https://wizzer.cn/archives/3385 , 转载请保留.