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
我在执行搜索查询时收到NoNodeAvailableException
。
我试过这个解决方案: https://stackoverflow.com/a/33875764/2616923 但它不起作用。
答案 0 :(得分:1)
尝试这种方式,您的代码似乎非常接近:
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
答案 1 :(得分:0)
尝试使用如下节点名称设置设置
Settings esSettings = Settings.builder().put("cluster.name", esClusterName)
.put("node.name",esNodeName)
答案 2 :(得分:0)
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.
答案 3 :(得分:0)
如果在全新安装Java和ElasticSearch的服务器上遇到此错误,请检查是否存在JAVA_HOME环境设置并将其设置为JRE的正确路径。例如:
JAVA_HOME = C:\ Program Files \ Java \ jre1.8.0_192