How to check if documents exist? And avoid errors

Hello All,
Have a simple ESQL script, to show counts in canvas.
There are scenarios where there are no documents in the index, and that is natural.
How can I check if the documents exist at all?

So instead of just running

Select count(*) from my-index

:arrow_up: Which resolves in canvas error, I would like to perform the following:

If docunet exist --> Select count(*) from my-index.
Else return 0

Thanks!

Hi, I've tested locally on an old version of kibana (7.6.2) and seems to work as expected:
if I have an empty index (because I've just created the index with no documents, or I've removed the documents) the query returns correctly 0 as result.
Could you please check that the index actually exist and second check that slightly changed query:

SELECT count(*) AS count from "my-index"

It also this one doesn't work, please provide the text of the error message so I can provide a better support from this

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.