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

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

问题描述

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

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.

ouput:

聚合结果在单独的字段中返回,命名为聚合。为了在此聚合数据中进行分页,大小和从不起作用。

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.

推荐答案

在弹性搜索中,无法分页聚合。如果指定大小,查询将不会给出准确的结果。因此,排序和分页的唯一方法是给出大小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天全站免登陆