简体   繁体   English

使用Java传输客户端连接到Elasticsearch。 获取请求不返回任何内容

[英]Connecting to Elasticsearch with java transport client. Get request returns nothing

I am new to elasticsearch but I am attempting to implement the basic java Get API from the elasticsearch documentation. 我是Elasticsearch的新手,但是我试图从elasticsearch文档中实现基本的Java Get API。 https://www.elastic.co/guide/en/elasticsearch/client/java-api/1.x/get.html https://www.elastic.co/guide/zh-CN/elasticsearch/client/java-api/1.x/get.html

I am using the TransportClient to connect to elasticsearch. 我正在使用TransportClient连接到elasticsearch。 From what I understand the TransportClient uses port 9300. Elasticsearch is on port 9200. When I call the get request with my specified cluster, index, type, and id, I just get back an empty list of fields. 据我了解,TransportClient使用端口9300。Elasticsearch在端口9200上。当我使用指定的集群,索引,类型和ID调用get请求时,我只获得了一个空字段列表。 I have already created the index in elasticsearch with the sense plugin and verified it through the head plugin. 我已经使用Sense插件在elasticsearch中创建了索引,并通过head插件对其进行了验证。 However, when I try to retrieve these values via my java implementation, I get nothing back. 但是,当我尝试通过我的java实现检索这些值时,我什么也没回来。 Here is a portion of my code below. 这是我下面的代码的一部分。

public String transportClientToElasticSearch()
{
   Settings settings = ImmutableSettings.settingsBuilder()
           .put("client.transport.sniff", "true")
           .put("cluster.name", "elasticsearch").build();

    Client client = new TransportClient(settings)
            .addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
            //.addTransportAddress(new InetSocketTransportAddress("localhost", 9200));

    client.admin().indices().prepareRefresh("index").execute();

   GetResponse response = client.prepareGet("index", "type", "id")
           .execute()
           .actionGet();

   String elasticResponse = response.getFields().toString();
   return elasticResponse;
}

My initial thought is that this is due to a difference in port numbers for the TransportClient and ES. 我最初的想法是,这是由于TransportClient和ES的端口号不同所致。 Any thoughts? 有什么想法吗? Thank you. 谢谢。

您应该只通过response.getSource()检索字段,这将产生Map<String, Object>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Elasticsearch Transport客户端Java客户端 - Elasticsearch transport client java client Elasticsearch 的 Java 传输客户端抛出 NoNodeAvailableException - Java Transport Client for Elasticsearch throws NoNodeAvailableException 如何使用Java传输客户端连接到ElasticSearch? - How to connect to ElasticSearch with Java transport client? Ubuntu 14.04上的ElasticSearch Java Transport Client NoNodeAvailableException - ElasticSearch Java Transport Client NoNodeAvailableException on Ubuntu 14.04 ElasticSearch:设置传输客户端 - ElasticSearch : setup transport client Elasticsearch传输客户端连接 - Elasticsearch Transport Client connection 服务器和客户端之间的简单连接。 客户端发送消息,服务器正确接收。 但是,当服务器尝试回复时,没有任何作用? - Simple connection between Server and Client. Client send message and server get it properly. But when the server tries to reply back nothing works? 使用Elasticsearch Transport客户端指定字段 - Specify fields with Elasticsearch Transport client clarifai2 Java客户端。 concept.name()导致Java NullPointerException,但concept.value返回置信度值 - clarifai2 java client. concept.name() results in Java NullPointerException but concept.value returns the confidence value 将Elasticsearch transport客户端升级到Rest客户端? - Upgrade Elasticsearch transport client to Rest client?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM