如何在弹性搜索查询中附加时间戳范围?

时间:2016-09-30 10:17:21

标签: mysql json elasticsearch elasticsearch-query

我正在尝试将弹性搜索查询作为POST请求执行,以便从我创建的索引中提取数据。索引中的数据是来自MySQL DB的表,通过logstash配置。

以下是我的请求和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 个答案:

答案 0 :(得分:1)

您只需删除$httpParamSerializer,因为只有在通过URL查询字符串发送查询时才需要它们(即对空格进行URL编码),但如果使用+查询,你不需要这样做

query_string