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"
}
}
})
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"index": "<index>",
"aggs": "<aggs>"
},
"name": "aggregate"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| index | Yes | ||
| aggs | Yes | ||
| query | No | ||
| size | No |