I have been moving from an auto-generated timestamp to a mapped one and query doesn’t work anymore. When using an auto-generated timestamp, I was able to perform this sort of query:
FilterBuilder filter = FilterBuilders.rangeFilter("_timestamp").from(zonedDateTime.toLocalDate().toString()).to(zonedDateTime.plusHours(1).toLocalDate().toString());
but also passing date expressions such as “now-1h” would work. Now that I have introduced the following mapping:
"collections": {
"_timestamp": {
"enabled": true,
"path": "my_date",
"ignore_missing": false
},
"properties": {
"author": {
"type": "string",
"index": "not_analyzed"
},
"name": {
"type": "string",
"analyzer": "lowercase"
},
"my_date": {
"type": "date"
}
}
}
And I store my_date as a Unix EPOCH format, I can’t query anymore:
FilterBuilders.rangeFilter("_timestamp").from(zonedDateTime.toLocalDate().toString()).to(zonedDateTime.plusHours(1).toLocalDate().toString());
Return empty results, while the query
FilterBuilders.rangeFilter("my_date").from(zonedDateTime.toLocalDate().toString()).to(zonedDateTime.plusHours(1).toLocalDate().toString());
Fails with an exception
from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"filtered":{"query":{"match_all":{}},"filter":{"range":{"my_date":{"from":"2015-09-04T19:52:15.001+01:00","to":"2015-09-04T21:52:15.001+01:00","include_lower":true,"include_upper":true}}}}}}]]]; nested: NumberFormatException[For input string: "2015-09-04T19:52:15.001+01:00"];
It looks like the only query that I can do is by using the numeric values of the timestamp, on my_date. Is there anything better I can hope for?