DAY 27
0
Elastic Stack on Cloud

# Percentiles

・這種聚合方式會回傳一個或多個百分位數，這些百分位數所代表的是一定百分比的觀察值出現的點，例如第95個百分位數是大於觀察值的95％的值。

・百分位數通常用於查找異常值。在正態分佈中，第0.13和第99.87個百分位數代表與平均值的三個標準差，任何超出三個標準偏差的數據通常被視為異常。

・預設會回傳[ 1, 5, 25, 50, 75, 95, 99 ]的百分位數。(第25、50、75位數就是第1四分位數、中位數、第3四分位數)

・回傳的數值是近似值

aggs query：

``````{
"aggs": {
"percentiles": {
}
}
}
}
``````

``````"aggregations" : {
"values" : {
"1.0" : 43.0,
"5.0" : 43.0,
"25.0" : 69.0,
"50.0" : 82.5,
"75.0" : 98.0,
"95.0" : 100.0,
"99.0" : 100.0
}
}
}
``````

aggs query：

``````{
"aggs": {
"percentiles": {
"percents": [0.13 ,90, 91, 92, 93, 93, 95, 99.5, 99.87]
}
}
}
}
``````

``````"aggregations" : {
"values" : {
"0.13" : 43.0,
"90.0" : 99.8,
"91.0" : 99.92,
"92.0" : 100.0,
"93.0" : 100.0,
"93.0" : 100.0,
"95.0" : 100.0,
"99.5" : 100.0,
"99.87" : 100.0
}
}
}
``````

aggs query

``````{
"aggs": {
"percentiles": {
"percents": [0.13 ,90, 91, 92, 93, 93, 95, 99.5, 99.87],
"script": {
"lang": "painless",
}
}
}
}
}
``````

``````"aggregations" : {
"values" : {
"0.13" : 23.0,
"90.0" : 79.8,
"91.0" : 79.92,
"92.0" : 80.0,
"93.0" : 80.0,
"93.0" : 80.0,
"95.0" : 80.0,
"99.5" : 80.0,
"99.87" : 80.0
}
}
}
``````

＃腳本的內容就別太在意，這邊只是簡單的告訴大家可以使用腳本依據使用者的目的調整結果

# Percentile Ranks

aggs query：

``````{
"aggs": {
"percentile_ranks": {
"values": [40]  #指定要推測的數值
}
}
}
}
``````

``````"aggregations" : {
"values" : {
"40.0" : 6.4102564102564115
}
}
}
``````

``````{
"aggs": {
"percentile_ranks": {
"values": [40],
"script": {
}
}
}
}
}
``````

``````"aggregations" : {
"values" : {
"40.0" : 12.820512820512823
}
}
}
``````