Elastic Search,是否可以获取搜索结果集中特定文档的索引?

Nic*_*sen 5 elasticsearch

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

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

Ram*_*amy 2

我正在使用 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());      
}
Run Code Online (Sandbox Code Playgroud)