2016-09-30 32 views
0

我試圖執行elasticsearch查詢作爲POST請求,以便從我創建的索引中提取數據。索引中的數據是來自MySQL DB的表格,通過logstash配置。我如何在我的elasticsearch查詢中追加時間戳範圍?

這裏是我的要求和JSON體:

http://localhost:9200/response_summary/_search

身體:

{ 
    "query": { 
     "query_string": { 
      "query": "transactionoperationstatus:\"charged\" AND api:\"payment\" AND operatorid:\"XL\" AND userid:*test AND time:\"2015-05-27*\" AND responsecode:(200+201)" 
     } 
    }, 
    "aggs": { 
     "total": { 
      "terms": { 
       "field": "userid" 
      }, 
    "aggs": { 
     "total": { 
      "sum": { 
       "script": "Double.parseDouble(doc['chargeamount'].value)" 
      } 
     } 
    } 
    } 
} 
} 

在上面JSON身體,我需要我的timestamp追加到query_string在在日期範圍內從索引獲取數據。我嘗試添加在查詢作爲結束:

AND timestamp:[2015-05-27T00:00:00.128Z+TO+2015-05-27T23:59:59.128Z]"

我要去哪裏錯了?任何幫助,將不勝感激。

回答

1

您只需要刪除+,因爲它們僅在通過URL查詢字符串發送查詢時(即對URL進行空間編碼時)是必需的,但如果使用query_string查詢,則無需執行那

AND timestamp:[2015-05-27T00:00:00.128Z TO 2015-05-27T23:59:59.128Z]" 
            ^^ 
             | | 
            remove these 
+0

感謝它的工作。 :) – Kulasangar

+1

很酷。同時刪除'(200 + 201)'中的'+' – Val