我想使用date_histogram做一個基于時間戳的滾動,并獲得每個時間范圍內數值的平均值。
{
"aggregations": {
"timestamp": {
"date_histogram": {
"欄位": "timestamp",
"間隔": "300s",
"offset": 0,
"順序": {
"_key": "升"
},
"keyed": false,
"min_doc_count": 0
},
"聚合": {
"myAgg": {
"avg": {
"欄位": "值"
}
}
}
}
}
}
然而,問題是,盡管數值(0.0 ~ 3.9)是浮動的,但聚合結果卻給出了浮動數值的平均值。 (E.g 1.1 -> 1, 2.2 -> 2).
。這里是一個示例結果。
"hits" : [
{
"_index" : "originals-20210915",
"_type" : "_doc",
"_score" : 5.6003222,
"_source" : {
"instanceName" : "LI9",
"metric" : "tps",
"值" : 0.36666667。
"timestamp" : "1631717705000"
}
},
{
"_index" : "originals-20210915",
"_type" : "_doc",
"_score" : 5.5940228,
"_source" : {
"instanceName" : "DN3",
"metric" : "tps",
"值" : 2.8333333,
"timestamp" : "1631717705000"
}
},
{
"_index" : "originals-20210915",
"_type" : "_doc",
"_score" : 5.5914664,
"_source" : {
"instanceName" : "LI9",
"metric" : "tps",
"值" : 0.13333334,
"timestamp" : "1631717700000"
}
},
{
"_index" : "originals-20210915",
"_type" : "_doc",
"_score" : 5.5914664,
"_source" : {
"instanceName" : "DN3",
"metric" : "tps",
"值" : 3.3,
"timestamp" : "1631717700000"
}
}
]
},
"聚合" : {
"instanceName" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "LI9",
"doc_count" : 2,
"timestamp" : {
"buckets" : [
{
"key_as_string" : "2021-09-15T14:55:00.000Z" 。
"key" : 1631717700000,
"doc_count" : 2,
"myAgg" : {
"值" : 0.0
}
}
]
}
},
{
"key" : "DN3",
"doc_count" : 2,
"timestamp" : {
"buckets" : [
{
"key_as_string" : "2021-09-15T14:55:00.000Z" 。
"key" : 1631717700000,
"doc_count" : 2,
"myAgg" : {
"值" : 2.5
}
}
]
}
}
]
我想知道是否有可能得到準確的平均值。
uj5u.com熱心網友回復:
根據你的分享,這可能是一個映射問題,你的欄位value是在integer中,而不是long。
因此,資料回傳時帶有索引值,但在后臺被投到了int,那么平均數就被錯誤地計算了。
你不能在索引后將映射從integer改為long,所以你需要使用_reindex來重新正確索引你的資料。
你的映射似乎是這樣的:
GET originals-20210915/_mapping
{ -20210915/_mapping
"originals-20210915" : {{/span>}。
"mappings" : {
"屬性" : {
"value" : {
"type" : "integer"
}
}
}
}
}
代替
{
"originals-20210915" : {
"mappings" : {
"屬性" : {
"value" : {
"type" : "float" // long
}
}
} }
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/315174.html
標籤:
