弹性搜索(Kibana)-布尔结果之间的相交 [英] Elastic search (Kibana) - intersect between boolean results

查看:81
本文介绍了弹性搜索(Kibana)-布尔结果之间的相交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Kibana遇到问题,如何正确过滤数据.基本上,我的目标是从以下数据结构中过滤通过或失败的测试.

I am facing a problem in Kibana how to correctly filter a data. Basically my aim is to filter PASSED or FAILED tests from the following data structure.

{
 "_index":"qa-reporting-2020-04",
 "_type":"qa-reporting",
 "_id":"456.0",
 "_version":1,
 "_score":null,
 "_source":{
  "TestId":"CXXX01",
  "TestStatus":0,
  "Issues":[
  ],
  "MetaData":{
     "TestName":"Test1",
     "LastException":null,
     "DurationMs":1980.5899000000002,
     "Platform":{
        "BrowserName":"chrome",
        "OS":"windows",
        "OsVersion":"10"
     },
     "Categories":[
        "Cat1",
        "Cat2",
        "CXXX01"
     ],
     "Priority":null,
     "TestStatusStr":"Passed",
     "JobName":"My-Demo/dev/ServerJob1",
     "Logs":"PASS  - Passed - CXXX01",
     "SuiteName":"Tests.ServerTests",
     "LastMessage":"PASS  - Passed - CXXX01: \n",
     "Environment":"dev"
  }
 }
}

问题在于,在某个时间(一天)内,日志将包含多个条目(例如,测试失败,并且在测试通过的同一天晚些时候).我有一个聚合查询,这给了我两个都不想要的结果.我希望有一个返回交集的结果,因此报告将包含失败/通过的测试.

The problem is that during a time (day), the logs will have several entries (e.g. the test failed and later in the same day the test passed). I have an aggregation query that gives me both results which is not desired. I want to have a result returning the intersection so the report will contain either failed/passed tests.

这是我的查询(我是乞讨者),它使我可以汇总失败并通过的特定测试.

Here is my query (I am begginer) which gives me aggregation for a specific test that failed and passed.

GET qa-reporting-*/_search
{"size": 0, 
 "query": {
  "bool": {
  "must": [
    {
      "match": {
        "MetaData.Environment": "dev"
      }
    },
    {
      "match": {
        "TestId": "CXXX01"
      }
    },
    {
      "range": {
        "Created": {
          "gte": "now-0d/d"
        }
      }
    }
  ]
}
},
"aggs": {
"tests": {
  "terms": {"field": "MetaData.TestStatusStr.keyword"}
  }
 }
}

它返回以下内容(摘录自整个对象)

It returns the following (excerpt from the entire object)

"aggregations": {
"tests": {
  "doc_count_error_upper_bound": 0,
  "sum_other_doc_count": 0,
  "buckets": [
    {
      "key": "Passed",
      "doc_count": 10
    },
    {
      "key": "Failed",
      "doc_count": 1
    }
  ]
 }
}

如上所述,如何在特定日期时间内获得失败/通过测试之间的交集?是否可以在Kibana中做到这一点,或者需要在其外部的脚本级别解决?

As above mentioned how to get the intersection between failed/passed tests during a specific date time? Is it possible to do it in Kibana or it needs to be solved on a script level outside of it?

当前我的报告如下:

 DateTime        | TestId | Status
 Apr 24,12:00    | CXXX01 | Failed
 Apr 24,15:00    | CXXX01 | Passed

想要的报告将只是上述状态的交集

Wanted report will be only the intersection of the above status

 Apr 24   | CXXX01 | Failed

 Apr 24   | CXXX01 | Passed

所以我认为最新的结果将具有更大的重要性.

So the latest result will have more weight I think.

推荐答案

我已经收集了两天的数据.每天两次.第1天的最后一个条目是失败",第2天的最后一个条目是通过"

I have taken data for two days. Two entries for each day. Last entry for day 1 is "Failed" and latest entry for day 2 is "Passed"

数据:

"hits" : [
      {
        "_index" : "index19",
        "_type" : "_doc",
        "_id" : "QKlosXEBuBOc-UQkKecO",
        "_score" : 1.0,
        "_source" : {
          "TestId" : "CXXX01",
          "TestStatus" : 0,
          "Issues" : [ ],
          "Created" : "2020-04-23T01:00:00",
          "MetaData" : {
            "TestName" : "Test1",
            "LastException" : null,
            "DurationMs" : 1980.5899000000002,
            "Platform" : {
              "BrowserName" : "chrome",
              "OS" : "windows",
              "OsVersion" : "10"
            },
            "Categories" : [
              "Cat1",
              "Cat2",
              "CXXX01"
            ],
            "Priority" : null,
            "TestStatusStr" : "Passed",
            "JobName" : "My-Demo/dev/ServerJob1",
            "Logs" : "PASS  - Passed - CXXX01",
            "SuiteName" : "Tests.ServerTests",
            "LastMessage" : "PASS  - Passed - CXXX01: \n",
            "Environment" : "dev"
          }
        }
      },
      {
        "_index" : "index19",
        "_type" : "_doc",
        "_id" : "QalosXEBuBOc-UQkieeR",
        "_score" : 1.0,
        "_source" : {
          "TestId" : "CXXX01",
          "TestStatus" : 0,
          "Issues" : [ ],
          "Created" : "2020-04-23T10:00:00",
          "MetaData" : {
            "TestName" : "Test1",
            "LastException" : null,
            "DurationMs" : 1980.5899000000002,
            "Platform" : {
              "BrowserName" : "chrome",
              "OS" : "windows",
              "OsVersion" : "10"
            },
            "Categories" : [
              "Cat1",
              "Cat2",
              "CXXX01"
            ],
            "Priority" : null,
            "TestStatusStr" : "Failed",
            "JobName" : "My-Demo/dev/ServerJob1",
            "Logs" : "PASS  - Passed - CXXX01",
            "SuiteName" : "Tests.ServerTests",
            "LastMessage" : "PASS  - Passed - CXXX01: \n",
            "Environment" : "dev"
          }
        }
      },
      {
        "_index" : "index19",
        "_type" : "_doc",
        "_id" : "QqlosXEBuBOc-UQkoue4",
        "_score" : 1.0,
        "_source" : {
          "TestId" : "CXXX01",
          "TestStatus" : 0,
          "Issues" : [ ],
          "Created" : "2020-04-24T10:00:00",
          "MetaData" : {
            "TestName" : "Test1",
            "LastException" : null,
            "DurationMs" : 1980.5899000000002,
            "Platform" : {
              "BrowserName" : "chrome",
              "OS" : "windows",
              "OsVersion" : "10"
            },
            "Categories" : [
              "Cat1",
              "Cat2",
              "CXXX01"
            ],
            "Priority" : null,
            "TestStatusStr" : "Failed",
            "JobName" : "My-Demo/dev/ServerJob1",
            "Logs" : "PASS  - Passed - CXXX01",
            "SuiteName" : "Tests.ServerTests",
            "LastMessage" : "PASS  - Passed - CXXX01: \n",
            "Environment" : "dev"
          }
        }
      },
      {
        "_index" : "index19",
        "_type" : "_doc",
        "_id" : "Q6losXEBuBOc-UQkwecl",
        "_score" : 1.0,
        "_source" : {
          "TestId" : "CXXX01",
          "TestStatus" : 0,
          "Issues" : [ ],
          "Created" : "2020-04-24T11:00:00",
          "MetaData" : {
            "TestName" : "Test1",
            "LastException" : null,
            "DurationMs" : 1980.5899000000002,
            "Platform" : {
              "BrowserName" : "chrome",
              "OS" : "windows",
              "OsVersion" : "10"
            },
            "Categories" : [
              "Cat1",
              "Cat2",
              "CXXX01"
            ],
            "Priority" : null,
            "TestStatusStr" : "Passed",
            "JobName" : "My-Demo/dev/ServerJob1",
            "Logs" : "PASS  - Passed - CXXX01",
            "SuiteName" : "Tests.ServerTests",
            "LastMessage" : "PASS  - Passed - CXXX01: \n",
            "Environment" : "dev"
          }
        }
      }
    ]

查询:我使用了

Query: I have used date_histogram to create bucket of each day and top_hits aggregation to get last document of that day

{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "MetaData.Environment": "dev"
          }
        },
        {
          "match": {
            "TestId": "CXXX01"
          }
        },
        {
          "range": {
            "Created": {
              "gte": "now-3d/d"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "daily":{
      "date_histogram": {
        "field": "Created",
        "interval": "day"
      },
      "aggs": {
        "last_result": {
          "top_hits": {
            "size": 1,
            "_source": ["MetaData.TestStatusStr"], 
            "sort": [
              {"Created":"desc"}]
          }
        }
      }
    }
  }
}

结果:

"aggregations" : {
    "daily" : {
      "buckets" : [
        {
          "key_as_string" : "2020-04-23T00:00:00.000Z",
          "key" : 1587600000000,
          "doc_count" : 2,
          "last_result" : {
            "hits" : {
              "total" : {
                "value" : 2,
                "relation" : "eq"
              },
              "max_score" : null,
              "hits" : [
                {
                  "_index" : "index19",
                  "_type" : "_doc",
                  "_id" : "QalosXEBuBOc-UQkieeR",
                  "_score" : null,
                  "_source" : {
                    "MetaData" : {
                      "TestStatusStr" : "Failed"
                    }
                  },
                  "sort" : [
                    1587636000000
                  ]
                }
              ]
            }
          }
        },
        {
          "key_as_string" : "2020-04-24T00:00:00.000Z",
          "key" : 1587686400000,
          "doc_count" : 2,
          "last_result" : {
            "hits" : {
              "total" : {
                "value" : 2,
                "relation" : "eq"
              },
              "max_score" : null,
              "hits" : [
                {
                  "_index" : "index19",
                  "_type" : "_doc",
                  "_id" : "Q6losXEBuBOc-UQkwecl",
                  "_score" : null,
                  "_source" : {
                    "MetaData" : {
                      "TestStatusStr" : "Passed"
                    }
                  },
                  "sort" : [
                    1587726000000
                  ]
                }
              ]
            }
          }
        }
      ]
    }
  }

这篇关于弹性搜索(Kibana)-布尔结果之间的相交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆