aggregate
Perform aggregation queries on search indices to group, analyze, and summarize data using terms, averages, date histograms, and multi-level aggregations.
Instructions
执行聚合查询
参数:
index: 索引名称
aggs: 聚合定义
query: 过滤条件(可选)
size: 返回文档数(默认 0,仅返回聚合结果)
示例 - 分组统计:
aggregate("orders", aggs={
"by_status": {"terms": {"field": "status"}}
})
示例 - 多级聚合:
aggregate("orders", aggs={
"by_category": {
"terms": {"field": "category"},
"aggs": {
"avg_price": {"avg": {"field": "price"}}
}
}
})
示例 - 日期直方图:
aggregate("logs", aggs={
"by_day": {
"date_histogram": {
"field": "@timestamp",
"calendar_interval": "day"
}
}
})
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| index | Yes | ||
| aggs | Yes | ||
| query | No | ||
| size | No |