we have 6.5 elk . and in dev tools following query works fine
POST /_xpack/sql?format=txt
{
"query": "select "@timestamp" from "mbeat-2020.01.23" where "@timestamp" >CAST('2020-01-23T05:00:00Z' AS TIMESTAMP)"
}
{
"query": "select "@timestamp" from "mbeat-2020.01.23" where "@timestamp" >CAST("2020-01-23T05:00:00Z" AS TIMESTAMP)"
}'
{"error":{"root_cause":[{"type":"x_content_parse_exception","reason":"[3:14] [sql/query] failed to parse object"}],"type":"x_content_parse_exception","reason":"[3:14] [sql/query] failed to parse object","caused_by":{"type":"json_parse_exception","reason":"Unexpected character ('2' (code 50)): was expecting comma to separate Object entries\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@1789e39b; line: 3, column: 102]"}},"status":400}[root@ukwysms00235 ~]#
it is not accepting CAST("2020-01-23T05:00:00Z" ,
i tried with single quotes , escaping with \ on both single /double quotes . but none is working
Hi As i said earlier is working in Dev tools kibana
POST /_xpack/sql?format=txt
{
"query": "select "@timestamp" from "mbeat-2020.01.23" where "@timestamp" >CAST('2020-01-23T05:00:00Z' AS TIMESTAMP)"
}
{
"query": "select "@timestamp" from "metricbeat.2020.01.23" where "@timestamp" >CAST('2020-01-23T05:00:00Z' AS TIMESTAMP)"
}'
{"error":{"root_cause":[{"type":"parsing_exception","reason":"line 1:88: identifiers must not start with a digit; please use double quotes"}],"type":"parsing_exception","reason":"line 1:88: identifiers must not start with a digit; please use double quotes"},"status":400}[root@ukwysms00235 ~]#
You need to escape the double quotes surrounding @timestamp. You look closely at this query - Sql access query not working via curl - there are backslashes there for the double quotes.
Also, CAST("2020-01-23T05:00:00Z" AS TIMESTAMP) should be used with single quotes: CAST('2020-01-23T05:00:00Z' AS TIMESTAMP).
2020 has to be replaced by single quote,backslash,double single quote 2020
CAST('''2020-01-28T05:00:00Z''' . backslash is removed in reply formatter here .
another problem is if i do max(@timestamp ) then , it returns double value instead of timestamp format both in using sql /json output . how to correct it .
And is there any way to extract json value via shell script or make json section in single line
max(date_field) indeed used to return a double value. But this bug is fixed in more recent versions: 6.6.3 is the earliest one that has the fix. For more details and more versions where the fix has been applied, have a look here: https://github.com/elastic/elasticsearch/pull/40377.
For json output (and on a single line), use format=json: /_xpack/sql?format=json
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.