Elasticsearch6. X invalid time range query bug

elasticsearch6.x time-range query invalid bug

1.es6.8.1 time range query, the original writing is as follows:

GET /oms_historyalarm.historyalarm_recent/historyalarm_recent/_search
{
    "query":{
             "range":{
                "fault_start_time":{
                    "from":"2019-10-28 00:00:00",
                    "to":"2019-10-28 17:46:03",
                    "format": "yyyy-MM-dd hh:mm:ss"
                  }
              }
      }
}

query results are as follows:

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}
2. Looked up many baidu resources but could not find a solution, finally went back to check the field type of es index, found that fault_start_time field storage type is String, in this case, es will default to participle query again, of course, but no return.

solution: simply identify the time field that needs to be filtered as a keyword and then es will not participle it. As follows:

GET /oms_historyalarm.historyalarm_recent/historyalarm_recent/_search
{
    "query":{
             "range":{
                 "fault_start_time.keyword":{
                     "from":"2019-10-28 00:00:00",
                     "to":"2019-10-28 17:46:03",
                     "format": "yyyy-MM-dd hh:mm:ss"
                  }
              }
    }
}

result: of course successful

hope you can help, if you have any questions please leave a comment.

Read More: