Mik*_*114 5 java curl elasticsearch
嗨,我正在尝试将我的ElasticSearch客户端连接到我的localhost并尝试从那里获取索引.
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.node.Node;
import org.elasticsearch.client.transport.*;
import org.elasticsearch.common.transport.*;
import java.io.IOException;
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
public class ESClient
{
public static void search()throws IOException
{
Node node;
node = nodeBuilder().clusterName("elasticsearch").node();
Client client;
client= new TransportClient()
.addTransportAddress(new InetSocketTransportAddress("localhost", 9200));
GetResponse response;
response= client.prepareGet("twitter", "tweet", "1").execute() .actionGet();
System.out.println(response.toString());
}
public static void main(String args[])throws IOException
{
search();
}
}
Run Code Online (Sandbox Code Playgroud)
我使用终端创建了索引.
curl -XPUT'http :// localhost:9200/twitter / 'curl -XPUT'http :// localhost:9200/twitter/_mapping/tweet'- d'{
"tweet":{"properties":{
"message" :{"type":"string","store":true}}
}}'
当我执行它时,抛出以下错误,
NFO:[Blackheath]无法获取[#transport#-1] [BLRMCB-C02L56J4DR53.local] [inet [localhost/127.0.0.1:9200]]的节点信息,断开连接... org.elasticsearch.transport.ReceiveTimeoutTransportException: [] [inet [localhost/127.0.0.1:9200]] [cluster:monitor/nodes/info] request_id [0]在org.elasticsearch.transport.TransportService $ TimeoutHandler.run(TransportService.java)[5002ms]之后超时366)java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)at java.lang.Thread.run(Thread.java) :745)
线程"main"中的异常org.elasticsearch.client.transport.NoNodeAvailableException:所有已配置的节点都不可用:[]位于org.elasticsearch的org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:278).在org.elasticsearch.client.support.AbstractClient.get(AbstractClient. java:193)atg.elasticsearch.client.transport.TransportClient.get(TransportClient.java:384)atg.elasticsearch.action.get.GetRequestBuilder.doExecute(GetRequestBuilder.java:201)at org.elasticsearch.action.ActionRequestBuilder .执行(ActionRequestBuilder.java:91)org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65)at .... ESClient.search(ESClient.java:30)at .... ESClient.main( ESClient.java:36)在太阳下.在sun.reflect.NalMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)的sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)的java.lang.reflect.Method.invoke上的reflect.NativeMethodAccessorImpl.invoke0(Native Method) Method.java:497)at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
有什么问题,谁能告诉我?
当我从使用 ElasticSearchAdapter 进行查询切换到使用 SparkStreamingAdapter 进行相同查询时,出现此错误。我只好把端口改成9300,然后就没有出现这个错误了。
这个问题/答案帮助我解决了这个问题: 为什么我不能通过 Java API 连接到 ElasticSearch?
| 归档时间: |
|
| 查看次数: |
3238 次 |
| 最近记录: |