# How to return a default string when no content matches

**URL:** <https://discuss.elastic.co/t/how-to-return-a-default-string-when-no-content-matches/355991>\
**Category:** Elasticsearch\
**Created:** [March 22, 2024, 1:51pm UTC](https://discuss.elastic.co/t/how-to-return-a-default-string-when-no-content-matches/355991 "2024-03-22T13:51:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kurian\_mathew](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kurian_mathew/32/132908_2.png) [@kurian\_mathew](https://discuss.elastic.co/u/kurian_mathew)\
**Post date:** [March 22, 2024, 1:51pm UTC](https://discuss.elastic.co/t/how-to-return-a-default-string-when-no-content-matches/355991/1 "2024-03-22T13:51:39Z")

</div>

I am trying to search the content on elasticsearch which will match a text. I want to return an default string if nothing matches to my search criteria.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 22, 2024, 2:14pm UTC](https://discuss.elastic.co/t/how-to-return-a-default-string-when-no-content-matches/355991/2 "2024-03-22T14:14:30Z")

</div>

Welcome!

Why not solving that on the client side?  
If the number of hits is 0, return whatever you want.

---

<div class="post-metadata">

**Author:** ![kurian\_mathew](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kurian_mathew/32/132908_2.png) [@kurian\_mathew](https://discuss.elastic.co/u/kurian_mathew)\
**Post date:** [March 22, 2024, 2:33pm UTC](https://discuss.elastic.co/t/how-to-return-a-default-string-when-no-content-matches/355991/3 "2024-03-22T14:33:25Z")

</div>

@dadoonet We are using elasticsearch as the data source in grafana. Since it is a variable in grafana it throws an error when used inside a MySQL query. So, I wanted to return a default value as No Data or something.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 22, 2024, 2:49pm UTC](https://discuss.elastic.co/t/how-to-return-a-default-string-when-no-content-matches/355991/4 "2024-03-22T14:49:47Z")

</div>

I'd ask Grafana to fix that behavior.

My 2 cents.

---

<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:** [April 19, 2024, 2:50pm UTC](https://discuss.elastic.co/t/how-to-return-a-default-string-when-no-content-matches/355991/5 "2024-04-19T14:50:39Z")

</div>

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