NumberFormatException For input string: \"now-1d/d\""

I´m executing a query using range agg on a date field (includes millis since epoch) but this leads to a NumberFormatException:
The mapping is:
"mappings": {
"_doc": {
"properties": {
"~timestamp": {
"type": "date"
}
}
}
}

"query": {
"range" : {
"~timestamp" : {
"gte" : "now-1d/d",
"lt" : "now/d"
}
}
}

"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "failed to create query: {\n "range" : {\n "~timestamp" : {\n "from" : "now-1d/d",\n "to" : "now/d",\n "include_lower" : true,\n "include_upper" : false,\n "boost" : 1.0\n }\n }\n}",
"index_uuid": "Y52J5NqWSBeGiY1pCywBIQ",
"index": "main_device-2018.09.27"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "main_device-2018.09.27",
"node": "u2uNIHjpR2qFGLuqeGAolA",
"reason": {
"type": "query_shard_exception",
"reason": "failed to create query: {\n "range" : {\n "~timestamp" : {\n "from" : "now-1d/d",\n "to" : "now/d",\n "include_lower" : true,\n "include_upper" : false,\n "boost" : 1.0\n }\n }\n}",
"index_uuid": "Y52J5NqWSBeGiY1pCywBIQ",
"index": "main_device-2018.09.27",
"caused_by": {
"type": "number_format_exception",
"reason": "For input string: "now-1d/d""
}
}
}
]
},
"status": 400
}

The error message suggests that the ~timestamp field is not mapped as a date in the main_device-2018.09.27 index. What could have happened is that when you indexed a document with an epoch millis timestamp, Elasticsearch dynamically mapped it as a field of type long instead of date.

You can retrieve the mapping of the index to check whether that's indeed the case by executing:

GET main_device-2018.09.27/_mapping
1 Like

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