irpas技术客

elasticsearch7.2 mapping设置分词器_云贵川_elasticsearch mapping 指定分词器

网络投稿 5998

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

关键点:

?源码关键点:

?


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #ElasticSearch #mapping #指定分词器 #java程序 #void