2017-08-09 74 views
0

我试图创建一个查询来计算在最后一天满足两个条件的情况。具有多个条件和时间范围的Elasticsearch查询

该查询显示了这两个条件的计数,但是当我尝试添加一个范围,它似乎符合所有文件:

GET logstash-*/_count 
    { 
     "query": { 
     "bool": { 
      "should": [ 
      { 
       "match": { 
       "rawmsg": { 
       "query": "Could not send Message.", 
       "type": "phrase" 
       } 
       } 
      }, 
      { 
       "match": { 
       "stack_trace": { 
        "query": "*WebServiceException*", 
        "type": "phrase" 
        } 
       } 
      } 
      ] 
     } 
     } 

} 

以下是我正在试图加入日期范围:

GET logstash-*/_count 
{ 
    "query": { 
    "bool": { 
     "should": [ 
     { 
      "match": { 
      "rawmsg": { 
      "query": "Could not send Message.", 
      "type": "phrase" 
      } 
      } 
     }, 
     { 
      "match": { 
      "stack_trace": { 
       "query": "*WebServiceException*", 
       "type": "phrase" 
       } 
      } 
     }, 
     { 

      "range" : { 
      "@timestamp" : { 
       "gte" : "now-1d/d", 
       "lt" : "now/d" 
      } 
     } 
     } 
     ] 
    } 
    } 

} 

回答

0

您使用的是must条款,从而有效地与OR而不是一个AND结合你的情况的should条款代替。

此外,范围查询的时间戳应为now/d-1d

0

我最终找到实现我需要的东西的方式有两种:

GET logstash-*/tcp_input/_count?q=stack_trace: *WebServiceException* AND rawmsg: "Could not send Message" AND @timestamp: [ now-30d TO now ] 

and 

GET logstash-*/_count 
{ 
    "query": { 
    "query_string": { 
     "query": """stack_trace: *WebServiceException* AND rawmsg: "Could not send Message" AND @timestamp: [ now-3d TO now]""", 
     "analyze_wildcard": true 
    } 
    } 
}