[英]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.