es - elasticsearch - aggs - metrics - extended

es - elasticsearch - aggs - metrics - extended,第1张

es - elasticsearch - aggs - metrics - extended

世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。

问:extended_stat有什么特点?
答:

问:extended_stats如何使用?
答:

# 删除
DELETE /extended_stats_test

# 映射
PUT /extended_stats_test
{
  "settings": {
    "number_of_shards": 1
  }, 
  "mappings": {
    "properties": {
      "name": {"type": "keyword"},
      "filter_type": {"type": "keyword"},
      "num": {"type": "integer"}
    }
  }
}

# 索引
POST /extended_stats_test/_bulk?routing=1&refresh
{"index": {"_id": 1}}
{"name": "hello", "filter_type": "t1", "num": 3}
{"index": {"_id": 2}}
{"name": "me", "filter_type": "t2", "num": 5}
{"index": {"_id": 3}}
{"name": "me", "filter_type": "t1", "num": 18}
{"index": {"_id": 4}}
{"name": "hello", "filter_type": "t1", "num": 20}
{"index": {"_id": 5}}
{"name": "good", "filter_type": "t1", "num": 28}
{"index": {"_id": 6}}
{"name": "me", "filter_type": "t2", "num": 50}
{"index": {"_id": 7}}
{"name": "good", "filter_type": "t1", "num": 58}
{"index": {"_id": 8}}
{"name": "hello", "filter_type": "t1", "num": 88}

# 搜索
GET /extended_stats_test/_search?size=0
{
  "aggs": {
    "extended_stats_test": {
      "extended_stats": {
        "field": "num"
      }
    }
  }
}

# 结果
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 8,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "extended_stats_test" : {
      "count" : 8,
      "min" : 3.0,
      "max" : 88.0,
      "avg" : 33.75,
      "sum" : 270.0,
      "sum_of_squares" : 15150.0,
      "variance" : 754.6875,
      "variance_population" : 754.6875,
      "variance_sampling" : 862.5,
      "std_deviation" : 27.471576219794887,
      "std_deviation_population" : 27.471576219794887,
      "std_deviation_sampling" : 29.368350311176826,
      "std_deviation_bounds" : {
        "upper" : 88.69315243958977,
        "lower" : -21.193152439589774,
        "upper_population" : 88.69315243958977,
        "lower_population" : -21.193152439589774,
        "upper_sampling" : 92.48670062235365,
        "lower_sampling" : -24.986700622353652
      }
    }
  }
}

# 搜索
GET /extended_stats_test/_search?size=0
{
  "aggs": {
    "extended_stats_test": {
      "extended_stats": {
        "field": "num",
        "sigma": 3
      }
    }
  }
}

# 结果
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 8,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "extended_stats_test" : {
      "count" : 8,
      "min" : 3.0,
      "max" : 88.0,
      "avg" : 33.75,
      "sum" : 270.0,
      "sum_of_squares" : 15150.0,
      "variance" : 754.6875,
      "variance_population" : 754.6875,
      "variance_sampling" : 862.5,
      "std_deviation" : 27.471576219794887,
      "std_deviation_population" : 27.471576219794887,
      "std_deviation_sampling" : 29.368350311176826,
      "std_deviation_bounds" : {
        "upper" : 116.16472865938466,
        "lower" : -48.664728659384664,
        "upper_population" : 116.16472865938466,
        "lower_population" : -48.664728659384664,
        "upper_sampling" : 121.85505093353048,
        "lower_sampling" : -54.35505093353048
      }
    }
  }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5432558.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存