我正在从REST API迁移到JAVA(因为我们希望从无数据节点优势中受益)。
我尝试以这种方式启动本地节点(启动对我来说似乎很好):
String localhostname = java.net.InetAddress.getLocalHost().getHostName();
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
settings.put("cluster.name", clusterName);
//Node name
settings.put("node.name", localhostname + "-eslocalnode");
//This is key to configure a data less node
/*
# 3. You want this node to be neither master nor data node, but
# to act as a "search load balancer" (fetching data from nodes,
# aggregating results, etc.)
#
# node.master: false
# node.data: false
*/
settings.put("node.master", false);
settings.put("node.data", false);
/*
# By default, multiple nodes are allowed to start from the same installation location
# to disable it, set the following:
# node.max_local_storage_nodes: 1
*/
settings.put("node.max_local_storage_nodes", 1);
/*
# Set a custom port for the node to node communication (9300 by default):
#
# transport.tcp.port: 9300
*/
if (tcpPort > 0)
settings.put("transport.tcp.port", tcpPort);
else
throw new IllegalArgumentException("tcpPort is not set");
/*
# Disable HTTP completely:
#
# http.enabled: false
I don't want the HTTP api to be available on the local data-less nodes, so I disable it
*/
settings.put("http.enabled", false);
/**
*
* DISCOVERY PART!!!
*
*
*
*/
settings.put("discovery.zen.ping.timeout", discoveryPingTimeout);
String unicastHostsArr[] = discoveryUnicastHosts.split("\\s*,\\s*");
if (unicastHostsArr.length > 0)
settings.put("discovery.zen.ping.unicast.hosts", unicastHostsArr);
settings.put("discovery.zen.ping.multicast.enabled", false);
Settings esSettings = settings.build();
Node newNode = NodeBuilder.nodeBuilder().local(true).settings(esSettings).node();
node = newNode.start();
(所有变量都已正确初始化我检查过)。特别是,unicastHosts只是一个主机,它是我们的开发服务器(它充满了重要数据),集群名称是相同的。
无论如何,如果我尝试使用like:
进行搜索 Client client = node.client();
ActionFuture<SearchResponse> searchFuture = client.search(new SearchRequest("journalindex"));
SearchResponse search = searchFuture.get();
我明白了:
Exception in thread "main" java.util.concurrent.ExecutionException: org.elasticsearch.cluster.block.ClusterBlockException: blocked by: [SERVICE_UNAVAILABLE/1/state not recovered / initialized];[SERVICE_UNAVAILABLE/2/no master];
at org.elasticsearch.common.util.concurrent.BaseFuture$Sync.getValue(BaseFuture.java:288)
at org.elasticsearch.common.util.concurrent.BaseFuture$Sync.get(BaseFuture.java:275)
at org.elasticsearch.common.util.concurrent.BaseFuture.get(BaseFuture.java:113)
at com.netaporter.cms.estests.test.EsDataLessNodeTest.main(EsDataLessNodeTest.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
关于为什么会发生这种情况的任何想法?