Settings settings =Settings.builder().put("cluster.name", "my-application").build();
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
System.out.println("Culster find");
IndicesAdminClient indicesAdminClient = client.admin().indices();
client.admin().indices().prepareCreate("index_naval").get();
client.admin().indices().prepareCreate("index_naval")
.setSettings(Settings.builder()
.put("index.number_of_shards", 3)
.put("index.number_of_replicas", 2)
)
.get();
client.admin().indices().prepareCreate("index_naval")
.addMapping("\"index_naval_type\": {\n" +
" \"properties\": {\n" +
" \"message\": {\n" +
" \"type\": \"text\"\n" +
" }\n" +
" }\n" +
"}")
.get();
上面是My Java,elasticSearchApp.java代码。 而我的elasticsearch.yml是。
cluster.name:my-application
xpack.security.transport.filter.allow:127.0.0.1
xpack.security.enabled:false
xpack.security.transport.ssl.enabled:false
xpack.security.http.ssl.enabled:false
node.name:my-rack
node.attr.rack:my-rack
node.master:true
node.data:true