Statistics 如何在ElasticSearch中从一组对象中获取平均值、最大值、最小值等
我使用Statistics 如何在ElasticSearch中从一组对象中获取平均值、最大值、最小值等,statistics,elasticsearch,Statistics,elasticsearch,我使用elasticsearchdb来存储基准测试的数据 我需要计算和检索一组值的平均值、最大值、最小值等 我有点像: Index = "myindex" Type = "mytype" { "query" : { "match_all" : {} }, "facets" : { "statload_time" : { "statistical" : { "field" : "lo
elasticsearch
db来存储基准测试的数据
我需要计算和检索一组值的平均值、最大值、最小值等
我有点像:
Index = "myindex"
Type = "mytype"
{
"query" : {
"match_all" : {}
},
"facets" : {
"statload_time" : {
"statistical" : {
"field" : "load_time"
}
},
"statexec_time" : {
"statistical" : {
"field" : "execution_time"
}
},
"statlog_time" : {
"statistical" : {
"field" : "log_time"
}
}
}
}
每个对象有3个字段:
"load_time", "execution_time", "log_time".
然后我运行基准测试,数据库中填充了数百条记录。现在,我将检索每个字段的平均值、最大值和最小值
我应该运行什么查询?
我尝试使用统计方面,但我总是得到一个“未认可的令牌异常”…您应该使用统计方面() 查询应该类似于:
Index = "myindex"
Type = "mytype"
{
"query" : {
"match_all" : {}
},
"facets" : {
"statload_time" : {
"statistical" : {
"field" : "load_time"
}
},
"statexec_time" : {
"statistical" : {
"field" : "execution_time"
}
},
"statlog_time" : {
"statistical" : {
"field" : "log_time"
}
}
}
}
正如医生所说:
统计数据包括计数、总数、平方和、平均值
(平均值)、最小值、最大值、方差和标准偏差
对两个文档编制索引后,查询的响应为:
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [ ]
},
"facets" : {
"statload_time" : {
"_type" : "statistical",
"count" : 2,
"total" : 7.0,
"min" : 2.0,
"max" : 5.0,
"mean" : 3.5,
"sum_of_squares" : 29.0,
"variance" : 2.25,
"std_deviation" : 1.5
},
"statexec_time" : {
"_type" : "statistical",
"count" : 2,
"total" : 12.0,
"min" : 5.0,
"max" : 7.0,
"mean" : 6.0,
"sum_of_squares" : 74.0,
"variance" : 1.0,
"std_deviation" : 1.0
},
"statlog_time" : {
"_type" : "statistical",
"count" : 2,
"total" : 16.0,
"min" : 7.0,
"max" : 9.0,
"mean" : 8.0,
"sum_of_squares" : 130.0,
"variance" : 1.0,
"std_deviation" : 1.0
}
}
}
我正在尝试此操作,但我得到了错误“Unrecognized token exception”,表示:{“error”:“MapperParsingException[未能解析];nested:JsonParseException[无法识别的令牌'load_time':应为('true'、'false'或'null')@CarmineGiangregorio您可以发布映射吗?