gpt4 book ai didi

elasticsearch - kibana中两个不同查询的除法计数

转载 作者:行者123 更新时间:2023-12-03 00:54:40 25 4
gpt4 key购买 nike

我试图创建一个Lucene表达式来显示两个查询的计数的除法。这两个查询都包含文本信息,并且两个结果都在消息字段中。我不确定如何正确编写此内容。到目前为止,我所做的事情没有任何运气-

doc['message'].value/doc['message'].value

第一次查询 message包含文本- "404 not found"
第二个查询 message包含文本为- "500 error"
我想做的是 count(404 not found)/count(500 error)
我将不胜感激任何帮助。

最佳答案

我将添加免责声明,仅运行两个单独的计数并像这样在客户端执行计算将明显更清洁:

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组合在一起的一种hacky方法
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表达式完成相同的操作

关于elasticsearch - kibana中两个不同查询的除法计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46437595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com