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

2024-02-28

我知道要在结果集中显示的特定文档的 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());      
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐