【问题标题】:How to control the elasticsearch aggregation results with From / Size?如何使用 From / Size 控制 elasticsearch 聚合结果?
【发布时间】:2017-08-19 16:07:56
【问题描述】:

我一直在尝试在弹性搜索术语聚合中添加分页。在查询中,我们可以添加分页,例如,

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

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

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

有什么方法可以使用函数或任何其他建议来创建分页吗?

【问题讨论】:

标签: elasticsearch pagination elasticsearch-plugin


【解决方案1】:

似乎您可能想要分区。 From the docs:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-22
    • 1970-01-01
    • 2021-09-20
    • 2014-10-22
    • 2018-12-11
    • 1970-01-01
    • 2017-02-06
    相关资源
    最近更新 更多