【发布时间】:2019-03-13 21:54:17
【问题描述】:
按照 Elastic Search 的文档,能够为其 API 设置 Java 环境。 但是,当尝试从名为 twitter 的索引访问时,在名为 tweet 的类型下,id 值为 1,响应为 null,控制台中没有错误。
以上代码
Settings settings = Settings.builder()
.put("cluster.name", "elasticsearch").build();
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
GetResponse response = client.prepareGet("twitter", "tweet", "2").get();
System.out.println(response.getFields());
client.close();
Same 的 Kibana 控制台数据
{
"_index": "twitter",
"_type": "tweet",
"_id": "2",
"_score": 1,
"_source": {
"user": "Rahul",
"post_date": "2009-11-15T14:12:12",
"message": "trying out Elasticsearch"
}
},
{
"_index": "twitter",
"_type": "tweet",
"_id": "1",
"_score": 1,
"_source": {
"user": "kimchy",
"post_date": "2009-11-15T14:12:12",
"message": "trying out Elasticsearch"
}
}
【问题讨论】:
-
可以加个链接来准备Get函数吗?
-
curl -XGET 'localhost:9200/twitter/tweet/0?pretty'
-
@Lax 只有当我尝试通过 java 访问它时,数据才能在 kibana 控制台中正常运行,它失败了,甚至检查了集群名称
标签: java elasticsearch kibana