【发布时间】:2015-05-21 21:59:58
【问题描述】:
在弹性搜索 java api 中,假设我正在使用此客户端构建索引数据
Node node = nodeBuilder().clusterName("es").node();
Client client = node.client();
IndexResponse response = client.prepareIndex("twitter", "tweet", "1")
.setSource(jsonBuilder()
.startObject()
.field("user", "kimchy")
.field("postDate", new Date())
.field("message", "trying out Elasticsearch")
.endObject()
)
.execute()
.actionGet();
此索引数据存储在文件夹 XYZ/elasticsearch/data 中。 我的问题是如何从其他客户端或其他代码中检索这些索引数据。有什么方法可以给路径,可以导入已经索引的数据,然后查询?
编辑:
其他电脑客户端的代码
Node node = nodeBuilder().clusterName("es").node();
Client client = node.client();
MatchQueryBuilder qb = QueryBuilders.matchQuery("user", "kimchy");
SearchRequestBuilder srb = client.prepareSearch("twitter").setTypes("tweet");
SearchResponse big = srb.setQuery(qb).execute().actionGet();
SearchHit[] results = big.getHits().getHits();
这表明
search.SearchPhaseExecutionException: Failed to execute phase [query], all shards failed
谢谢
艾莉亚
【问题讨论】:
-
为什么不直接在 localhost:9200 上查询它,您可以开始使用 match_all 查询 { "query" : {"match_all":{}}
-
@AkashYadav ,就是这样,我不会在我的计算机上查询,我只会索引它,然后我会将包含数据的文件夹传输到其他计算机,我将在那里查询它,我怎样才能检索这个已经索引的数据。谢谢
-
过程将是相同的,只需在其他系统上安装弹性搜索并将数据文件夹放在节点文件夹中,通常位于 ubuntu 系统中的 /usr/share/elasticsearch/data/ 位置,一切都会正常工作与它在您的系统中的工作方式相同。您必须使用与上面提到的相同的索引名称和相同的 url。希望这会有所帮助。
-
@AkashYadav 我尝试了同样的事情......请参阅上面的编辑部分。但它显示了这个异常.. search.SearchPhaseExecutionException: Failed to execute phase [query], all shards failed.. 知道这是怎么回事。还是非常感谢
标签: import elasticsearch