2017-08-09 101 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 
    } 
    } 
}