弹性搜索中的聚合+排序+分页 [英] Aggregation + sorting +pagination in elastic search

查看:39
本文介绍了弹性搜索中的聚合+排序+分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在其中一个索引中进行聚合 + 排序 + 分页.

I need to do an aggregation + sorting + pagination in one of the indexes.

我了解了弹性搜索的内部功能,

I learned about internal functionality of Elastic search,

我总共有 5 个分片,它将对各个分片进行排序并获取结果,默认情况下每个分片将返回 10 条记录.然后再次对这 50 条记录进行排序,它将获取前 10 条记录,因为默认大小为 10.

I have 5 total shards, it will sort the individual shards and fetch the result, by default each shard will return in 10 records. Then the 50 records are sorted again and it will fetch the top 10 record since by default size is 10.

输出:

聚合结果在名为aggregations"的单独字段中返回.为了在此聚合数据中进行分页,size 和 from 不起作用.

The aggregated results are returned in separate field named as "aggregations".In order to do pagination in this aggregated data,size and from are not working.

厌倦了做 termBuilder.size(500),现在这个链接的逻辑有所不同(http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html)

So tired of doing termBuilder.size(500), now the logic was differs as per this link (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html)

这会导致数据不准确.

谁能建议我如何处理聚合 + 分页.

Can any one suggest me how to deal with aggregation + pagination.

推荐答案

在 elasticsearch 中,无法对聚合进行分页.如果指定了大小,查询将不会给出准确的结果.所以,排序和分页的唯一方法是给size 0并返回所有文档,然后通过将所有结果累加到列表中以供进一步操作来获得所需的结果.

In elasticsearch, it's not possible to paginate an aggregation. The query will not give accurate results if size is specified. So, the only way to do sorting and pagination is to give size 0 and return all the documents and then, get the required results by accumulating all the results in a list for further operation.

这篇关于弹性搜索中的聚合+排序+分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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