elasticsearch – 弹性搜索,是否可以在搜索结果集中获取特定文档的索引?

我知道我想在结果集中显示的特定文档的ID,但我不知道它将在哪个页面上显示结果.弹性搜索是否可以告诉它返回特定文档所在的页面?

我的猜测是不可能的.我目前的方法是在加载文档ID后运行查询,并为查询返回一个非常大(全部)的结果集.我在此列表中找到了id,然后再次运行查询,加载我要在页面上显示的所有数据.如果我可以避免它,我宁愿不运行两次查询.

最佳答案 我正在使用JAVA API,我得到的索引,类型,ID和来源如下.

SearchResponse response = client.prepareSearch().execute().actionGet();
SearchHit[] documents = response.getHits().getHits();
for(SearchHit document : documents)
{
    System.out.println("document index :: " + document.getIndex());
    System.out.println("document type :: " + document.getType());
    System.out.println("document id :: " + document.getId());
    System.out.println("document source JSON :: " + document.getSourceAsString());      
}
点赞