【问题标题】:Elasticsearch -- get count of log type in last 24 hoursElasticsearch -- 获取过去 24 小时内的日志类型计数
【发布时间】:2017-05-18 16:05:16
【问题描述】:

所以我的 Elasticsearch 索引中有 3 种类型的日志-

CA、CT 和 Acc

我正在尝试查询 Elasticsearch 以获取通话前 24 小时的每个计数,但我没有太多运气将它们组合在一起。

打电话

10.10.23.45:9200/filebeat-*/_count

{
 "query":{
    "term": {"type":"ct"}
 }
}

让我计数,但尝试添加时间范围已被证明是徒劳的。当我尝试向同一个查询添加范围时 - 它不起作用

我尝试使用:

{
    "query":{
        "term": {"type":"ct"},
        "range":{
            "date":{
                "gte": "now-1d/d",
                "lt" : "now"
            }
        }
    }
}

但是被退回了

{
"error": {
    "root_cause": [
        {
            "type": "parsing_exception",
            "reason": "[term] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
            "line": 5,
            "col": 3
        }
    ],
    "type": "parsing_exception",
    "reason": "[term] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
    "line": 5,
    "col": 3
},
"status": 400
}

【问题讨论】:

    标签: api search elasticsearch


    【解决方案1】:

    您需要使用 Bool Query 将两种类型的查询合二为一。试试这个吧。

    POST _search
    {
      "query": {
        "bool" : {
          "must" : {
            "term": {"type":"ct"}
          },
          "must" : {
            "range":{
                "date":{
                    "gte": "now-1d/d",
                    "lt" : "now"
                }
            }
          }
        }
      }
    }
    

    【讨论】:

    • 这似乎不太适合我——我得到了以下结果——当我对我得到的相同数据进行计数时:6071579 { "took": 4, "timed_out" :假,“_shards”:{“total”:32,“成功”:32,“失败”:0},“hits”:{“total”:0,“max_score”:null,“hits”:[] } }
    【解决方案2】:

    以下内容对我有用(注意——这是发送到 elasticsearch:9200/index/_search 的帖子)

    {"query":{"bool":{"must":[{"query_string":{"analyze_wildcard":true,"query":"type:\"acc\""}},{"range":{"@timestamp":{"gte":"now-1h","lte":"now","format":"epoch_millis"}}}]}}}
    

    【讨论】:

      猜你喜欢
      • 2022-09-23
      • 1970-01-01
      • 2014-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-05
      • 1970-01-01
      • 2016-10-08
      相关资源
      最近更新 更多