How to use query_string with date in elasticsearch

Viewed 260

Does query_string support GT operation with date?

{
  "_source": {
    "includes": [
      "id"
    ]
  },
  "size": 20,
  "sort": [
    {
      "published": {
        "order": "DESC"
      }
    }
  ],
  "query": {
    "query_string": {
      "query": "updated > (2014-11-01T00:00:00Z)"
    }
  }
}

Throw Failed to parse query [updated > (2014-11-01T00:00:00Z)]

What is wrong with my query?

Mapping is:

"updated": {
    "type": "date",
    "format": "yyyy-MM-dd HH:mm:ssZ"
}
1 Answers

The query needs to be like this, i.e. in the Lucene expression language

  "query": "updated:{2014-11-01 TO *}"

However, you'd be better off using a simple range query:

"range": {
   "updated": {
      "gt": "2014-11-01T00:00:00Z"
   }
}
Related