# Is there a way to return true/false if documents exists for the given query?

**URL:** <https://discuss.elastic.co/t/is-there-a-way-to-return-true-false-if-documents-exists-for-the-given-query/316965>\
**Category:** Elasticsearch\
**Tags:** eql-elastic-query-language\
**Created:** [October 19, 2022, 7:58am UTC](https://discuss.elastic.co/t/is-there-a-way-to-return-true-false-if-documents-exists-for-the-given-query/316965 "2022-10-19T07:58:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hamza\_Khalid](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hamza_khalid/32/103313_2.png) [@Hamza\_Khalid](https://discuss.elastic.co/u/Hamza_Khalid)\
**Post date:** [October 19, 2022, 7:58am UTC](https://discuss.elastic.co/t/is-there-a-way-to-return-true-false-if-documents-exists-for-the-given-query/316965/1 "2022-10-19T07:58:11Z")

</div>

I have a query:

GET users/\_search  
{ "from": 0, "size": 20,  
"query": {  
"match\_all": {}  
}

What i want to achieve is if the above query returns even a single document i get the response as true and if no document is returned i get false.

How is this possible?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [October 19, 2022, 11:55am UTC](https://discuss.elastic.co/t/is-there-a-way-to-return-true-false-if-documents-exists-for-the-given-query/316965/2 "2022-10-19T11:55:21Z")

</div>

@Hamza_Khalid

I don't understand why do this logic in the query, you can manipulate the query response in your application.  
What is the reason for doing this?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 19, 2022, 12:01pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-return-true-false-if-documents-exists-for-the-given-query/316965/3 "2022-10-19T12:01:34Z")

</div>

Set size to 1 and check whether any matching document was returned.

---

<div class="post-metadata">

**Author:** ![Hamza\_Khalid](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hamza_khalid/32/103313_2.png) [@Hamza\_Khalid](https://discuss.elastic.co/u/Hamza_Khalid)\
**Post date:** [October 19, 2022, 12:09pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-return-true-false-if-documents-exists-for-the-given-query/316965/4 "2022-10-19T12:09:06Z")

</div>

I want to return a category list of users so for example if my query returns 10 users i want to show those 10 users in a new tab(category list) and this category list should only pop up if the query returns any records else the category list won't be created.

---

<div class="post-metadata">

**Author:** ![Hamza\_Khalid](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hamza_khalid/32/103313_2.png) [@Hamza\_Khalid](https://discuss.elastic.co/u/Hamza_Khalid)\
**Post date:** [October 19, 2022, 12:26pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-return-true-false-if-documents-exists-for-the-given-query/316965/5 "2022-10-19T12:26:57Z")

</div>

Thank you for the reply but i think you misunderstood the question. whatever i set the size to it will return results doesn't matter what the query is my question is. Is there a way to get response as true if my query return 1 or more document and false if my query returns no document.

For example:

```auto
curl -XGET 'http://localhost:9200/twitter/tweet/_search/exists' -d '
{
    "query" : {
    "term" : { "user" : "kimchy" }
    }
}'

```

Response:

```auto
"exists" : true

```

i found this in different disscussion but this not working for me i'm getting no handler found for uri exists.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 19, 2022, 12:37pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-return-true-false-if-documents-exists-for-the-given-query/316965/6 "2022-10-19T12:37:47Z")

</div>

> [@Hamza\_Khalid](#):
>
> Is there a way to get response as true if my query return 1 or more document and false if my query returns no document.

No, not that I am aware of, which is why I suggested handling this in your application code.

---

<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 16, 2022, 12:38pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-return-true-false-if-documents-exists-for-the-given-query/316965/7 "2022-11-16T12:38:18Z")

</div>

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