# How to check if documents exist? And avoid errors

**URL:** <https://discuss.elastic.co/t/how-to-check-if-documents-exist-and-avoid-errors/253253>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [October 26, 2020, 2:18am UTC](https://discuss.elastic.co/t/how-to-check-if-documents-exist-and-avoid-errors/253253 "2020-10-26T02:18:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [October 26, 2020, 2:18am UTC](https://discuss.elastic.co/t/how-to-check-if-documents-exist-and-avoid-errors/253253/1 "2020-10-26T02:18:26Z")

</div>

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

```auto
Select count(*) from my-index

```

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

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

```

Thanks!

---

<div class="post-metadata">

**Author:** ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)\
**Post date:** [November 2, 2020, 3:39pm UTC](https://discuss.elastic.co/t/how-to-check-if-documents-exist-and-avoid-errors/253253/2 "2020-11-02T15:39:06Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 30, 2020, 3:39pm UTC](https://discuss.elastic.co/t/how-to-check-if-documents-exist-and-avoid-errors/253253/3 "2020-11-30T15:39:13Z")

</div>

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