如何使用 From/Size 控制 elasticsearch 聚合结果? [英] How to control the elasticsearch aggregation results with From / Size?

查看:28
本文介绍了如何使用 From/Size 控制 elasticsearch 聚合结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在 elasticsearch 术语聚合中添加分页.在查询中,我们可以添加分页,如

I have been trying to add pagination in elasticsearch term aggregation. In query we can add the pagination like,

 {
    "from": 0, // to add the start to control the pagination
    "size": 10,
    "query": { } 
 }

这很清楚,但是当我想在聚合中添加分页时,我阅读了很多关于它的内容,但找不到任何东西,我的代码看起来像这样,

this is pretty clear, but when I want to add pagination to aggregation, I read a lot about it, but I couldn't find anything, My code looks like this,

{
  "from": 0,
  "size": 0,
  "aggs": {
    "group_by_name": {
      "terms": {
        "field": "name",
        "size": 20
      },
      "aggs": {
        "top_tag_hits": {
          "top_hits": {
            "size": 1
          }
        }
      }
    }
  }
}

有没有办法用函数或任何其他建议创建分页?

Is there any way to create pagination with a function or any other suggestions?

推荐答案

看来您可能想要分区.来自文档:

有时在单个请求/响应对中需要处理太多独特的术语,因此将分析分解为多个请求会很有用.这可以通过在查询时将字段的值分组到多个分区中并在每个请求中仅处理一个分区来实现.

Sometimes there are too many unique terms to process in a single request/response pair so it can be useful to break the analysis up into multiple requests. This can be achieved by grouping the field’s values into a number of partitions at query-time and processing only one partition in each request.

基本上你添加 "include": { "partition": n, "num_partitions": x },,其中 n 是页面,x 是页数.

Basically you add "include": { "partition": n, "num_partitions": x },, where n is the page and x is the number of pages.

不幸的是,此功能是最近才添加的.如果在产生此功能的 GitHub Issue 上可以相信标签,您将至少需要使用 Elasticsearch 5.2 或更高版本.

Unfortunately this feature was added fairly recently. If the tags can be believed on the GitHub Issue which spawned this feature, you'll need to be on at least Elasticsearch 5.2 or better.

这篇关于如何使用 From/Size 控制 elasticsearch 聚合结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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