I recently started using sql from elasticsearch. i am trying to use below API
POST _sql?format=csv
{
"query": "SELECT SERVICE_NAME,Success,count() From"my_inde" WHERE "@timestamp" >= NOW() - INTERVAL 3 HOURS group by SERVICE_NAME,Success"
}
where Success is my scripted field. However I am getting below error.
Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.
Or use markdown style like:
```
CODE
```
This is the icon to use if you are not using markdown format:
There's a live preview panel for exactly this reasons.
Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
If Success was created with Kibana's scripted fields functionality, you won't be able to use it in SQL since those are accessible to Kibana only.
However, you might potentially be able to compute that field as an SQL expression and potentially also group by that expression (or it's aliased name). Something along the lines of:
SELECT SERVICE_NAME, some_field > 0 AS Success, count() FROM "my_index" WHERE "@timestamp" >= NOW() - INTERVAL 3 HOURS GROUP BY SERVICE_NAME, Success
@bogdan.pintea : Thanks a lot it is almost working , I am getting below response. Can we print success/failure instead of true false. I am getting below output.
Query :
SELECT SERVICE_NAME,ERRORSTATUS.keyword ='0' AS Success,count() FROM "my_visualization" WHERE "@timestamp" >= NOW() - INTERVAL 1 HOURS and SERVICE_NAME IN ('My_service') group by SERVICE_NAME,Success
You'll probably want something like SELECT count(ERRORSTATUS.keyword) FROM .. GROUP BY ERRORSTATUS.keyword. It's standard SQL, any good tutorial should touch on it.
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.