弹性搜索,是否可以在搜索结果集中获取特定文档的索引? [英] Elastic Search, is it possible to get the index of a specific document in a search result set?

查看:82
本文介绍了弹性搜索,是否可以在搜索结果集中获取特定文档的索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我想在我的结果集中显示的特定文档的ID,但是我不知道该结果的哪个页面。可以通过弹性搜索来告诉它返回特定文档的页面吗?

I know the id of a specific document I want to show in my result set, but I don't know which page of the results it will be on. Is it possible with elastic search to tell it to return the page that a specific document is on?

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

My guess is this is not possible. My current approach is to run the query once loading just the documents ids and return a very large (all) result set for the query. I find the id in this list, then I run the query again loading all of the data I want to show on the page. I'd prefer not to run the query twice if I can avoid it.

推荐答案

我正在使用JAVA API,索引,类型,ID和来源如下。

I am using JAVA API and I am getting the index, type, id and source as follows.

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());      
}

这篇关于弹性搜索,是否可以在搜索结果集中获取特定文档的索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆