I use ElasticSearch
v5.0 in java application and create index. But the 9300 port can't work.
Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{wT9q99-KSTObzOpHJGj5bA}{127.0.0.1}{127.0.0.1:9300}]]
This is java code:
public static void main(String[] args) {
Settings settings = Settings.builder()
.put("client.transport.sniff", true)
.put("cluster.name", "clusterTest")
.build();
client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("127.0.0.1", 9300)));
List<String> jsonList = DataFactory.getInitJsonData();
String indexname = "esIndex";
String type = "esType";
ElasticApp app = new ElasticApp();
app.createIndex(indexname, type, jsonList);
}
private void createIndex(String indexname, String type, List<String> jsonList){
try {
IndexRequestBuilder requestBuilder = client.prepareIndex(indexname, type, "1").setCreate(true);
for (int i=0;i<jsonList.size();i++){
requestBuilder.setSource(XContentFactory.jsonBuilder()
.startObject()
.field(jsonList.get(i))
.endObject()
).execute().actionGet();
}
System.out.print("Create Index Success");
} catch (IOException e) {
e.printStackTrace();
System.out.print("Fdiled");
}
}