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" } } } ] } } }