简体   繁体   English

如何使用From / Size控制Elasticsearch聚合结果?

[英]How to control the elasticsearch aggregation results with From / Size?

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? 有什么方法可以创建带有函数的分页或任何其他建议?

Seems like you probably want partitions. 好像您可能想要分区。 From the docs: 从文档:

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. 这可以通过在查询时将字段的值分为多个分区并在每个请求中仅处理一个分区来实现。

Basically you add "include": { "partition": n, "num_partitions": x }, , where n is the page and x is the number of pages. 基本上,您添加"include": { "partition": n, "num_partitions": x }, ,,其中n是页面, x是页面数。

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. 如果可以在产生此功能的GitHub Issue上相信这些标签,则至少需要使用Elasticsearch 5.2或更高版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM