排序记录(下降)后,如何对n个文档数量进行总和聚合?松紧带

发布于 2025-02-11 16:55:20 字数 725 浏览 0 评论 0原文

{因此,我想要20/6至20/4之间的最新30个文档,并在这30个最新文档的field duration_seconds上执行总和聚合。我们尝试过对TOP_HIT的多次聚合,排序术语,但随后我们获得了所有DOC的总和,在20/6至20/4之间

  "size": 1,
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "create_datetime": {
              "gte": "2022-04-20",
              "lte": "2022-06-20"
            }
          }
        }
      ]
    }
  },
  "sort": [
    {
      "create_datetime": {
        "order": "desc"
      }
    }
  ],
  "aggs": {
    "videosession": {
      "sampler": {
        "shard_size":30
      },
      "aggs": {
        "sum_duration_seconds": {
          "sum": {
            "field": "duration_seconds"
          }
        }
      }
    }
  }
}```

{so, i want latest 30 document between 20/6 to 20/4 and perform the sum aggregation on field duration_seconds of those 30 latest doc. we had tried multiple aggregation on that like top_hits, terms for sorting but then we got the sum of all doc between 20/6 to 20/4}

  "size": 1,
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "create_datetime": {
              "gte": "2022-04-20",
              "lte": "2022-06-20"
            }
          }
        }
      ]
    }
  },
  "sort": [
    {
      "create_datetime": {
        "order": "desc"
      }
    }
  ],
  "aggs": {
    "videosession": {
      "sampler": {
        "shard_size":30
      },
      "aggs": {
        "sum_duration_seconds": {
          "sum": {
            "field": "duration_seconds"
          }
        }
      }
    }
  }
}```

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文