过去一个小时刚刚下载并安装了elasticsearch 1.3.2
打开到端口9200和9300:9400的IP表
在/ etc / hosts中设置我的计算机名称和IP
头模块和护理人员已安装且运行平稳
卷曲在本地主机上工作完美
将所有jar从下载中复制到eclipse中,因此版本相同
--Java–
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.elasticsearch.index.query.QueryBuilders; public class Test{ public static void main(String[] args) { Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "elastictest").build(); TransportClient transportClient = new TransportClient(settings); Client client = transportClient.addTransportAddress(new InetSocketTransportAddress("143.79.236.xxx",9300));//just masking ip with xxx for SO Question try{ SearchResponse response = client.prepareSearch().setQuery(QueryBuilders.matchQuery("url", "twitter")).setSize(5).execute().actionGet();//bunch of urls indexed String output = response.toString(); System.out.println(output); }catch(Exception e){ e.printStackTrace(); } client.close(); } }
-输出-
log4j:WARN No appenders could be found for logger (org.elasticsearch.plugins). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [] at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:298) at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:214) at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:105) at org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:330) at org.elasticsearch.client.transport.TransportClient.search(TransportClient.java:421) at org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:1097) at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91) at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65) at Test.main(Test.java:20)
更新:现在我真的很困惑。我只是按了日食3次。2次收到上述错误。1次搜索成功!全新的Centos 6.5 vps,全新的jdk已安装。然后安装了elasticsearch,其他什么也没做。
更新:运行./bin/elasticsearch控制台后
[2014-09-18 08:56:13,694][INFO ][node ] [Acrobat] version[1.3.2], pid[2978], build[dee175d/2014-08-13T14:29:30Z] [2014-09-18 08:56:13,695][INFO ][node ] [Acrobat] initializing ... [2014-09-18 08:56:13,703][INFO ][plugins ] [Acrobat] loaded [], sites [head, paramedic] [2014-09-18 08:56:15,941][WARN ][common.network ] failed to resolve local host, fallback to loopback java.net.UnknownHostException: elasticsearchtest: elasticsearchtest: Name or service not known at java.net.InetAddress.getLocalHost(InetAddress.java:1473) at org.elasticsearch.common.network.NetworkUtils.<clinit>(NetworkUtils.java:54) at org.elasticsearch.transport.netty.NettyTransport.<init>(NettyTransport.java:204) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.elasticsearch.common.inject.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:54) at org.elasticsearch.common.inject.ConstructorInjector.construct(ConstructorInjector.java:86) at org.elasticsearch.common.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:98) at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:45) at org.elasticsearch.common.inject.InjectorImpl.callInContext(InjectorImpl.java:837) at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:42) at org.elasticsearch.common.inject.Scopes$1$1.get(Scopes.java:57) at org.elasticsearch.common.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:45) at org.elasticsearch.common.inject.FactoryProxy.get(FactoryProxy.java:52) at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:45) at org.elasticsearch.common.inject.InjectorImpl.callInContext(InjectorImpl.java:837) at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:42) at org.elasticsearch.common.inject.Scopes$1$1.get(Scopes.java:57) at org.elasticsearch.common.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:45) at org.elasticsearch.common.inject.SingleParameterInjector.inject(SingleParameterInjector.java:42) at org.elasticsearch.common.inject.SingleParameterInjector.getAll(SingleParameterInjector.java:66) at org.elasticsearch.common.inject.ConstructorInjector.construct(ConstructorInjector.java:85) at org.elasticsearch.common.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:98) at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:45) at org.elasticsearch.common.inject.InjectorImpl.callInContext(InjectorImpl.java:837) at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:42) at org.elasticsearch.common.inject.Scopes$1$1.get(Scopes.java:57) at org.elasticsearch.common.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:45) at org.elasticsearch.common.inject.SingleParameterInjector.inject(SingleParameterInjector.java:42) at org.elasticsearch.common.inject.SingleParameterInjector.getAll(SingleParameterInjector.java:66) at org.elasticsearch.common.inject.ConstructorInjector.construct(ConstructorInjector.java:85) at org.elasticsearch.common.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:98) at org.elasticsearch.common.inject.FactoryProxy.get(FactoryProxy.java:52) at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:45) at org.elasticsearch.common.inject.InjectorImpl.callInContext(InjectorImpl.java:837) at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:42) at org.elasticsearch.common.inject.Scopes$1$1.get(Scopes.java:57) at org.elasticsearch.common.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:45) at org.elasticsearch.common.inject.SingleParameterInjector.inject(SingleParameterInjector.java:42) at org.elasticsearch.common.inject.SingleParameterInjector.getAll(SingleParameterInjector.java:66) at org.elasticsearch.common.inject.ConstructorInjector.construct(ConstructorInjector.java:85) at org.elasticsearch.common.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:98) at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:45) at org.elasticsearch.common.inject.InjectorImpl.callInContext(InjectorImpl.java:837) at org.elasticsearch.common.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:42) at org.elasticsearch.common.inject.Scopes$1$1.get(Scopes.java:57) at org.elasticsearch.common.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:45) at org.elasticsearch.common.inject.InjectorBuilder$1.call(InjectorBuilder.java:200) at org.elasticsearch.common.inject.InjectorBuilder$1.call(InjectorBuilder.java:193) at org.elasticsearch.common.inject.InjectorImpl.callInContext(InjectorImpl.java:830) at org.elasticsearch.common.inject.InjectorBuilder.loadEagerSingletons(InjectorBuilder.java:193) at org.elasticsearch.common.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:175) at org.elasticsearch.common.inject.InjectorBuilder.build(InjectorBuilder.java:110) at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:93) at org.elasticsearch.common.inject.Guice.createInjector(Guice.java:70) at org.elasticsearch.common.inject.ModulesBuilder.createInjector(ModulesBuilder.java:59) at org.elasticsearch.node.internal.InternalNode.<init>(InternalNode.java:192) at org.elasticsearch.node.NodeBuilder.build(NodeBuilder.java:159) at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:70) at org.elasticsearch.bootstrap.Bootstrap.main(Bootstrap.java:203) at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:32) Caused by: java.net.UnknownHostException: elasticsearchtest: Name or service not known at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901) at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293) at java.net.InetAddress.getLocalHost(InetAddress.java:1469) ... 62 more [2014-09-18 08:56:16,937][INFO ][node ] [Acrobat] initialized [2014-09-18 08:56:16,937][INFO ][node ] [Acrobat] starting ... [2014-09-18 08:56:17,110][INFO ][transport ] [Acrobat] bound_address {inet[/0:0:0:0:0:0:0:0:9300]}, publish_address {inet[/143.79.236.31:9300]} [2014-09-18 08:56:17,126][INFO ][discovery ] [Acrobat] elastictest/QvSNFajjQ9SFjU7WOdjaLw [2014-09-18 08:56:20,145][INFO ][cluster.service ] [Acrobat] new_master [Acrobat][QvSNFajjQ9SFjU7WOdjaLw][localhost][inet[/143.79.236.31:9300]], reason: zen-disco-join (elected_as_master) [2014-09-18 08:56:20,212][INFO ][http ] [Acrobat] bound_address {inet[/0:0:0:0:0:0:0:0:9200]}, publish_address {inet[/143.79.236.31:9200]} [2014-09-18 08:56:20,214][INFO ][node ] [Acrobat] started
-elasticsearch.yml中的群集配置-
################################### Cluster ################################### # Cluster name identifies your cluster for auto-discovery. If you're running # multiple clusters on the same network, make sure you're using unique names. # cluster.name: elastictest
Elasticsearch设置位于中$ES_HOME/config/elasticsearch.yml。在那里,如果cluster.name注释掉了该设置,则意味着ES几乎可以采用任何群集名称。因此,在您的代码中,cluster.nameas "elastictest"可能是问题所在。试试这个:
$ES_HOME/config/elasticsearch.yml
cluster.name
"elastictest"
Client client = new TransportClient() .addTransportAddress(new InetSocketTransportAddress( "143.79.236.xxx", 9300));