2016-09-30 29 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