创建mapping,和curl中完全对应,同样指定分析器为ik
public void createMapping(String index,String type) throws IOException{
XContentBuilder builder = XContentFactory.jsonBuilder()
.startObject()
.startObject(type)
.startObject("_all")
.field("indexAnalyzer", "ik")
.field("searchAnalyzer", "ik")
.field("term_vector", "no")
.field("store", "false")
.endObject()
.startObject("properties")
.startObject("content")
.field("type", "string")
.field("store", "no")
.field("term_vector", "with_positions_offsets")
.field("indexAnalyzer", "ik")
.field("searchAnalyzer", "ik")
.field("include_in_all", "true")
.field("boost", 9)
.endObject()
.endObject()
.endObject()
.endObject();
PutMappingRequest mapping = Requests.putMappingRequest(index).type(type).source(builder);
client.admin().indices().putMapping(mapping).actionGet();
}