I must be doing something wrong, but I’m not sure what …
I’m trying to do a SQL query like this (names change to protect the guilty):
"query": "SELECT nodename,state FROM nodes WHERE @timestamp > subdate(now(), INTERVAL 5 MINUTE)"
What I want is all the name/state pairs from the past 5 minutes from the index ‘nodes’. What I get is the error message:
"The following query method is not supported: subdate"
Looking at the documentation (and searching discourse and the github site), I see there are two functions that appear to be similar: ‘subdate’ and ‘date_sub’ … both give me the same error.
What am I doing wrong? Is there a better way to accomplish this goal?
I’m using the tarball installation of version 1.3.0 …
Hi @DrEdWilliams - I’m still coming up to speed on some of this, but at first glance, the syntax of your query looks correct. I suspect there might be some kind of data type mismatch issue going on - is @timestamp configured as a
date type in your index mapping? OpenSearch will do its best to detect the appropriate mapping if you haven’t explicitly provided one, but it’s not always perfect at it.
I’ll see if I can consult some subject matter experts for you.
@nateynate - @timestamp is the standard timestamp field coming in from metricbeat
Thanks for reporting the issue! I just did a quick test and found function
NOW() seems broken. Both
INTERVAL works well as below, although
SELECT NOW() gave me NPE. I’m investigating and looking into the code.
SELECT subdate(date('2008-01-02'), INTERVAL 5 MINUTE)
"name": """subdate(date('2008-01-02'), INTERVAL 5 MINUTE)""",
Whoah, I think that was some kind of speed record in bug identification. Thanks for bringing it here, @DrEdWilliams
@daichen - That makes sense!
Further experimentation with the adddate/subdate functions seem to work if I provide fields instead of the now() function – an dwhenever I try to pull in ‘now()’, I have issues.
It’s probably related, but the ‘curdate()’ function seems to cause the same behavior – I expect they are connected behind the scenes, but something else to check.
@DrEdWilliams Thanks for more info. After looking into the code, I can confirm that some date functions like
NOW() can only be used alone. Here is the issue opened earlier: Date time query improvement · Issue #46 · opensearch-project/sql · GitHub. I’ve commented there and we need to complete the date function support so they can work altogether. Sorry for the inconvenience caused!