2017-05-18 44 views
0

所以我有3种在我Elasticsearch日志首页 -Elasticsearch - 获取日志类型的数量在过去24小时内

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 
} 

回答

1

您需要使用布尔查询到将两种类型的查询合并为一个。试试这个。

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

这似乎并不很为我 - 我有工作下面回来了 - 当我为相同的数据做一个数,我得到:6071579 { \t “花”:4, \t “TIMED_OUT”:假的, \t “_shards”:{ \t \t“TOT人“:32, \t \t ”成功“:32, \t \t ”失败“:0 \t}, \t ”命中“:{ \t \t ”总“:0, \t \t ”MAX_SCORE“:空, \t \t“hits”:[] \t} } –

0

对我下面的工作(注 - 这是发送到elasticsearch一个帖子:9200 /指数/ _search)

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