Parse date error

Executing the query:

 {
"query": {
"bool": {
  "must": [
    {
      "match": {
        "foo": "pattern"
      }
    },
    {
      "range": {
        "@timestamp": {
          "gte": "bar.start_time",
          "format": "yyyy-MM-dd'T'HH:mm:ss,SSSZ"
        }
      }
    }
  ]
}
}
}

I get the exception

   "reason": 
      "type": "parse_exception",
      "reason": "failed to parse date field [bar.start_time] with format [yyyy-MM-dd'T'HH:mm:ss,SSSZ]",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "Parse failure at index [0] of [bar.start_time]"
      }
    }

I really wonder how this can happen because bar.start_time is of the format: "2017-11-16T11:35:07,821Z" and if I replace bar.start_time with the concrete value of it, e.g. "2017-11-16T11:35:07,821Z", the query works. Anyone can help?

Hi Luc,

In the date range query documentation it states that you should inform one date in the gte clause (grater than equal) and not a field name.

So, for example, if you want to find documents that have their field bar.start_time grater than equal 2017-11-16T11:35:07,821Z:

GET my_index/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "bar.start_time": {
              "gte": "2015-11-16T11:35:07,821Z",
              "format": "yyyy-MM-dd'T'HH:mm:ss,SSSZ"
            }
          }
        }
      ]
    }
  }
}

Hope it helps!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.