# Help in Query (possible sub-query ?)

**URL:** <https://discuss.elastic.co/t/help-in-query-possible-sub-query/211388>\
**Category:** Elasticsearch\
**Created:** [December 10, 2019, 11:15pm UTC](https://discuss.elastic.co/t/help-in-query-possible-sub-query/211388 "2019-12-10T23:15:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![saz](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@saz](https://discuss.elastic.co/u/saz)\
**Post date:** [December 10, 2019, 11:15pm UTC](https://discuss.elastic.co/t/help-in-query-possible-sub-query/211388/1 "2019-12-10T23:15:50Z")

</div>

Hi ,

I have some documents like this and I have no clue on querying the documents without using a  
subquery.

`{ request-id : 1234 , status : error }`  
`{ request-id : 1234 , error-info : system }`  
`{ request-id : 12345 , status : error }`  
`{ request-id : 123456 , status : error }`

In the above , there are documents with indicates some error but it could be an error by system or  
internal error which has no error-info.

I trying to get the query to get the count of only documents which has error status from system ? From above , request-id with 1234 is matched and count is 1. The problem is see is that when filter  
documents with status as "error" and error-info "system" , the documents with any other "error"  
also gets in the way. Is there a way to do like SQL , "select reques-id whose status = "error" and erro-info = system"

---

<div class="post-metadata">

**Author:** ![rameshkr1994](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rameshkr1994/32/59029_2.png) [@rameshkr1994](https://discuss.elastic.co/u/rameshkr1994)\
**Post date:** [December 12, 2019, 2:45pm UTC](https://discuss.elastic.co/t/help-in-query-possible-sub-query/211388/2 "2019-12-12T14:45:57Z")

</div>

Hi @saz.

Yes you can implement as SQL.

Thanks  
HadoopHelp

---

<div class="post-metadata">

**Author:** ![saz](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@saz](https://discuss.elastic.co/u/saz)\
**Post date:** [December 13, 2019, 9:46pm UTC](https://discuss.elastic.co/t/help-in-query-possible-sub-query/211388/3 "2019-12-13T21:46:24Z")

</div>

Thank you .. we don't have xpack to use it. Is that the only way to query such data ?

---

<div class="post-metadata">

**Author:** ![rameshkr1994](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rameshkr1994/32/59029_2.png) [@rameshkr1994](https://discuss.elastic.co/u/rameshkr1994)\
**Post date:** [December 17, 2019, 11:57am UTC](https://discuss.elastic.co/t/help-in-query-possible-sub-query/211388/4 "2019-12-17T11:57:32Z")

</div>

Hi @saz.

Please try with this :-  
`{ "query": { "bool": { "must": [{ "term": { "status .keyword": { "value": "error", "boost": 1 } } }, { "term": { "erro-info.keyword": { "value": "system", "boost": 1 } } }] } } }`

> i hope this will work in your use case!!!

Thanks  
HadoopHelp

---

<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:** [January 14, 2020, 11:57am UTC](https://discuss.elastic.co/t/help-in-query-possible-sub-query/211388/5 "2020-01-14T11:57:43Z")

</div>

Closed on January 14, 2020, 11:57am UTC

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