* 创建mapping(feid("indexAnalyzer","ik")该字段分词IK索引 ;feid("searchAnalyzer","ik")该字段分词ik查询;具体分词插件请看IK分词插件说明) * @param indices 索引名称; * @param mappingType 索引类型 * @throws Exception * public static void createMapping(String indices,String mappingType)throws Exception{ TransportClient client = TransportSingleton.getTransport(); XContentBuilder builder = XContentFactory.jsonBuilder() .startObject() .startObject(indices) .startObject("properties") .startObject("id").field("type", "integer").endObject() .startObject("kw").field("type", "text").field("analyzer", "ik_max_word").endObject() .startObject("edate").field("type", "date").endObject() .endObject() .endObject() .endObject(); PutMappingRequest mapping = Requests.putMappingRequest(indices).type(mappingType).source(builder); client.admin().indices().putMapping(mapping).actionGet(); client.close(); } ============================================================= ** * 创建索引名称 * @param indices 索引名称 * public static void createCluterName(String indices) throws UnknownHostException { TransportClient client = TransportSingleton.getTransport(); client.admin().indices().prepareCreate(indices).execute().actionGet(); client.close(); } 分享: