Reputation: 677
I want to create a connection with elasticsearch in order to exectue a query
this is my exception déc. 28, 2017 10:06:11 AM
org.elasticsearch.plugins.PluginsService <init>
INFOS: [Shockwave] modules [], plugins [], sites []
Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: []]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:290)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:207)
at org.elasticsearch.client.transport.support.TransportProxyClient.execute(TransportProxyClient.java:55)
at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:288)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:359)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:86)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:56)
at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:64)
at com.intelcom.boot.App.<init>(App.java:59)
at com.intelcom.boot.App.main(App.java:71)
this is my main code
TransportClient client ;
InetSocketTransportAddress node = new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300);
Settings settings = Settings.builder().put("cluster.name", "elasticsearch").put("client.transport.sniff", true)
.build();
client = TransportClient.builder().settings(settings).build();
SearchRequestBuilder builder = client.prepareSearch("index")
.setTypes("index_type")
.setQuery(QueryBuilders.boolQuery().must(QueryBuilders.matchQuery("_all", "Rabat")));
System.out.println(builder);
SearchResponse response = builder.get(); //<<<==== error
thanks for helping
Upvotes: 0
Views: 119
Reputation: 595
your initialization of es transport client is wrong:
Here is an simple example of initialization:
Settings settings = Settings.builder()
.put("cluster.name", "myClusterName").build();
TransportClient client = new PreBuiltTransportClient(settings).addTransportAddress(new TransportAddress(InetAddress.getByName("host1"), 9300))
.addTransportAddress(new TransportAddress(InetAddress.getByName("host2"), 9300));
more refer to link
Upvotes: 1