我对弹性搜索概念很陌生。我正在尝试使用弹性搜索构建一个简单的应用程序。
public class App
{
public static void main( String[] args )
{
try {
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
ElasticOperations.addDocToIndex(client, ElasticUtility.getJsonMap("Sandesha", "male", "jsandesh08@gmail.com", "Hassan"));
System.out.println("Doc added");
client.close();
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
但是,当试图运行此程序时,我得到NoNodeAvailableException
。
线程中的异常" main" NoNodeAvailableException [没有配置的节点可用:[{#transport#-1} {w1bSLAN-TFWUHE1PA3qDeQ} {localhost} {127.0.0.1:9300}]] at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:347) at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:245) 在org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59) at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:363) 在org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:408) 在org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80) 在org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54) at com.sandesha.elasticsearch.Elastic.ElasticOperations.addDocToIndex(ElasticOperations.java:11) 在com.sandesha.elasticsearch.Elastic.App.main(App.java:27)
请帮我解决这个问题。
我的ElasticOperations
课程是,
public class ElasticOperations {
public static void addDocToIndex(TransportClient client, Map<String,Object> jsonMap)
{
client.prepareIndex("customers", "personal").setSource(jsonMap).execute().actionGet();
}
}
我的ElasticUtility
课程看起来像,
public class ElasticUtility {
public static Map<String, Object> getJsonMap(String name, String gender, String email, String city)
{
Map<String,Object> jsonMap = new HashMap<String, Object>();
jsonMap.put("name", name);
jsonMap.put("gender", gender);
jsonMap.put("email", email);
jsonMap.put("city", city);
return jsonMap;
}
}
谢谢。
答案 0 :(得分:0)
我认为你的群集名称不匹配。如果您的群集名称不是“弹性搜索”,则可能是问题。
在浏览器中转到http://localhost:9200并获取群集名称。然后,尝试将群集名称属性添加到TransportClient,如下所示:
Settings settings = Settings.builder()
.put("cluster.name", "elasticsearch_foo").build();
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));