我要添加免责声明,这将是显著吸尘器只运行两个单独的罪名,并执行计算在客户端这样的:
GET /INDEX/_search
{
"size": 0,
"aggs": {
"types": {
"terms": {
"field": "type",
"size": 10
}
}
}
}
这将返回类似(除了使用您的区别键而不是在我的例子类型):
"aggregations": {
"types": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Article",
"doc_count": 881
},
{
"key": "Page",
"doc_count": 301
}
]
}
利用这一点,把你独特的计数和计算平均值。
通过以上所指出,这里是哈克的方式,我能够从放在一起(通过单个请求)this
GET /INDEX/_search
{
"size": 0,
"aggs": {
"parent_agg": {
"terms": {
"script": "'This approach is a weird hack'"
},
"aggs": {
"four_oh_fours": {
"filter": {
"term": {
"message": "404 not found"
}
},
"aggs": {
"count": {
"value_count": {
"field": "_index"
}
}
}
},
"five_hundreds": {
"filter": {
"term": {
"message": "500 error"
}
},
"aggs": {
"count": {
"value_count": {
"field": "_index"
}
}
}
},
"404s_over_500s": {
"bucket_script": {
"buckets_path": {
"four_oh_fours": "four_oh_fours.count",
"five_hundreds": "five_hundreds.count"
},
"script": "return params.four_oh_fours/(params.five_hundreds == 0 ? 1: params.five_hundreds)"
}
}
}
}
}
}
这应该返回基于脚本中计算的总价值。
如果有人可以提供一个方法,除了这两个,我很乐意看到它。希望这可以帮助。
编辑 - 通过“表达式”类型完成相同的脚本而不是无痛(默认)。只需更换与以下上面的脚本值:
"script": {
"inline": "four_oh_fours/(five_hundreds == 0 ? 1 : five_hundreds)",
"lang": "expression"
}
更新脚本在这里完成通过Lucene的同样的事情表达式
我想我可以帮你,我只是想确认我理解正确的问:你需要一个计算结果,其中包含完全“404未找到”的不同文档的数量除以包含完全“500错误”输出的不同文档的数量作为浮点数? 假设对此,是否将消息字段映射为“关键字”类型?如果不是,我需要对你想要的输出做更多的说明。 – Miek
@MikeMichaels是的,你是正确的输出,我想也消息字段映射为“关键字”类型 – jonny