TransportClient 新建index,mappings dynamic_templates。
Posted on 2018-03-16 09:51 和风细雨汪汪 阅读(544) 评论(0) 收藏 举报public void createIndex(TransportClient client, String index){ CreateIndexRequest request = new CreateIndexRequest(index); String setting ="" +"{" +" \"number_of_shards\": 3," +" \"number_of_replicas\": 1," +" \"search_analyzer\": \"ik_max_word\"" +"}"; String mapping ="{" +" \"dynamic_templates\": [" +" {" +" \"strings\": {" +" \"match\": \"*\"," +" \"match_mapping_type\": \"string\"," +" \"mapping\": {" +" \"type\": \"string\"," +" \"analyzer\": \"ik_max_word\"," +" \"fields\": {" +" \"raw\": {" +" \"type\": \"string\"," +" \"index\": \"not_analyzed\"," +" \"ignore_above\": 256" +" }" +" }" +" }" +" }" +" }" +" ]" +" }"; request.settings(setting).mapping("_default_", mapping); client.admin().indices().create(request); }
POST http://192.168.1.12:9200/test { "settings": { "number_of_shards": 3, "number_of_replicas": 1, "search_analyzer": "ik_max_word" }, "mappings": { "_default_": { "dynamic_templates": [ { "strings": { "match": "*", "match_mapping_type": "string", "mapping": { "type": "string", "analyzer": "ik_max_word", "fields": { "raw": { "type": "string", "index": "not_analyzed", "ignore_above": 2560 } } } } } ] } } }
{ "settings": { "number_of_shards": 5, "number_of_replicas": 1, "search_analyzer": "ik_max_word" }, "mappings": { "_default_": { "dynamic_templates": [ { "strings": { "match": "*", "unmatch": "id", "match_mapping_type": "string", "mapping": { "type": "string", "analyzer": "ik_max_word", "fields": { "raw": { "type": "string", "index": "not_analyzed", "ignore_above": 2560 } } } } }, { "integers": { "match": "id", "mapping": { "type": "integer" } } } ] } } }
善于将复杂问题简单化
浙公网安备 33010602011771号