Settings settings = Settings.settingsBuilder()
.put("cluster.name", "logging_elasticsearch")
.build();
TransportClient client = TransportClient.builder()
.settings(settings)
.build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByAddress(new byte[]{10,100,30,62}), 9300));
SearchResponse response = client.prepareSearch("logstash-2016.09.08")
.setTypes("type1", "type2")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.termQuery("multi", "test")) // Query
.setPostFilter(QueryBuilders.rangeQuery("age").from(12).to(18)) // Filter
.setFrom(0).setSize(60).setExplain(true)
.execute()
.actionGet();
elasticsearch.yml
I'm getting a NoNodeAvailableException
when executing my search query.
I tried this solution: https://stackoverflow.com/a/33875764/2616923 but it did not work.
Try this way, your code seems to be pretty close:
Settings settings = Settings.settingsBuilder()
.put("cluster.name", "<elasticsearch-cluster-name>")
.build();
Client client = new TransportClient.Builder()
.settings(settings)
.build()
.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("<elasticsearch-network-host>", <elasticsearch-transport-client-port|default 9300>)));
==== elasticsearch.yml ====
cluster.name: <elasticsearch-cluster-name>
node.name: <elasticsearch-network-host>
network.host: <elasticsearch-network-host>
network.bind_host: 0
Try to put settings with node name like below,
Settings esSettings = Settings.builder().put("cluster.name", esClusterName)
.put("node.name",esNodeName)
I have created transport client with more parameters. Below code is perfectly running in production.
Settings settingsBuilder = Settings.builder()
.put("cluster.name", DBPropertyUtil.getPropertyByName("es.cluster")).put("client.transport.sniff", true).put("client.transport.ignore_cluster_name", true).build();
Client client = new PreBuiltTransportClient(settingsBuilder)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), port));
Put respective details for host, port, clusterName as per your elasticSearch Servers config.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With