gpt4 book ai didi

elasticsearch - sql到es:在agg上获取限制页面和订单结果

转载 作者:行者123 更新时间:2023-12-03 02:14:05 25 4
gpt4 key购买 nike

SELECT
max( timestamp ) AS first_time,
min( timestamp ) AS last_time,
src_ip,
threat_target ,
count(*) as count
FROM
traffic
GROUP BY
src_ip,
threat_target

ORDER BY
first_time desc

LIMIT 0 ,10
我想获得此结果,但我不知道如何获取 limit size以及在哪里使用 sort
{
"size": 0,
"aggregations": {
"src_ip": {
"aggregations": {
"threat_target": {
"aggregations": {
"last_time": {
"max": {
"field": "`timestamp`"
}
},
"first_time": {
"min": {
"field": "`timestamp`"
}
}
},
"terms": {
"field": "threat_target.keyword"
}
}
},
"terms": {
"field": "src_ip.keyword"
}

}
}
}

最佳答案

Elastic Search通常不支持

  • Aggregation分页,但是复合聚合提供了一种分页聚合的方法。

  • Unlike the other multi-bucket aggregation the composite aggregation can be used to paginate all buckets from a multi-level aggregation efficiently.


    摘自 Composite-Aggregation ES文档。
    检查: THIS
  • 除了“ORDER BY first_time desc”外,下面的查询应该可以很好地运行。我不认为除了分组字段(src_ip,
    可能有威胁)。
     GET traffic/_search
    {
    "size": 0,
    "aggs": {
    "my_bucket": {
    "composite": {
    "size": 2, //<=========== PAGE SIZE
    /*"after":{ // <========== INCLUDE THIS FROM Second request onwards, passing after_key of the last output here for next page
    "src_ip" : "1.2.3.5",
    "threat_target" : "T3"
    },*/
    "sources": [
    {

    "src_ip": {
    "terms": {
    "field": "source_ip",
    "order": "desc"
    }
    }
    },
    {
    "threat_target": {
    "terms": {
    "field": "threat_target"
    }
    }
    }
    ]
    },
    "aggs": {
    "first_time": {
    "max": {
    "field": "first_time"
    }
    }
    }
    }
    }
    }
  • 关于elasticsearch - sql到es:在agg上获取限制页面和订单结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63967386/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com