需求:先得到最近1小时的数据,然后用composite aggregation的方法实现ouyu-number字段的分页输出功能:
GET /bj-sip_register/_search
{
"size": 0,
"aggs": {
"today": {
"filter": {
"range": {
"@timestamp" :{
"gte":"now-1h",
"lt":"now"
}
}
},
"aggs": {
"result": {
"composite" : {
"sources": [
{
"ouyu-number": {
"terms": {
"field": "ouyu-number.keyword"
}
}
}
]
}
}
}
}
}
}
输出提示如下,我的理解是filter aggs后面不能跟composite aggs,那么用桶的前提下这个需求该如何实现?谢谢!{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "[composite] aggregation cannot be used with a parent aggregation of type: [FilterAggregatorFactory]"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "bj-sip_register",
"node": "Z7tobMU1RgSwndaSKhdJww",
"reason": {
"type": "illegal_argument_exception",
"reason": "[composite] aggregation cannot be used with a parent aggregation of type: [FilterAggregatorFactory]"
}
}
],
"caused_by": {
"type": "illegal_argument_exception",
"reason": "[composite] aggregation cannot be used with a parent aggregation of type: [FilterAggregatorFactory]",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "[composite] aggregation cannot be used with a parent aggregation of type: [FilterAggregatorFactory]"
}
}
},
"status": 400
}
2 个回复
bellengao - 博客: https://www.jianshu.com/u/e0088e3e2127
赞同来自: sailershen
{
"size": 0,
"aggs": {
"number": {
"filter": {
"range": {
"@timestamp" :{ "gte":"now-1h", "lt":"now" }
}
},
"aggs": {
"y": {
"terms": {
"field": "ouyu-number.keyword"
},
"aggs": {
"sales_bucket_sort": {
"bucket_sort": {
"sort": [
{
"_key": {
"order": "asc"
}
}
],
"from": 1,
"size": 2
}
}
}
}
}
}
}
}
sailershen
赞同来自: