I have a task to somehow check before querying ES that user provided a correct timestamps for time range. Specifically I need to resolve expressions like "now", "now-1d", "now+1h" to valid timestamp. Any idea how I can do it without doing hardcore stuff like trying on my own to parse strings to date format?
In other words I need to convert "now-1h" to something like date(2023, 10, 07,x,x,x) or any other valid format.
Maybe I can somehow check it with ES first by sending some simple query?
Thank you
You can validate your entire query using validate command. So you can craft a small date range query and put a timestamp there.
Saying this I think you will be just wasting time. If dates are incorrect you will get a very quick response from elasticsearch, which you can then send back to the user. You also don't need to do anything to resolve expressions like "now", "now-1d", "now+1h" before sending them to elasticsearch. Elasticsearch supports these and a fews other expression when it expects a timestamp.