# How to do a "subquery"

**URL:** <https://discuss.elastic.co/t/how-to-do-a-subquery/15886>\
**Category:** Elasticsearch\
**Created:** [February 19, 2014, 5:15am UTC](https://discuss.elastic.co/t/how-to-do-a-subquery/15886 "2014-02-19T05:15:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![11141](https://avatars.discourse-cdn.com/v4/letter/1/e19adc/32.png) [@11141](https://discuss.elastic.co/u/11141)\
**Post date:** [February 19, 2014, 5:15am UTC](https://discuss.elastic.co/t/how-to-do-a-subquery/15886/1 "2014-02-19T05:15:47Z")

</div>

Hi all

I have data like following

{ "id":1, "name":"Tom", "query":"apple"}  
{ "id":2, "name":"Tom", "query":"orange"}  
{ "id":3, "name":"Jack", "query":"apple"}  
{ "id":4, "name":"Jack", "query":"banana"}

which query/search can i use to get:

"which queries that queried by the men who query orange"

for example:  
Tom and Jack query orange  
they also query apple and banana

so the result is "apple, orange, banaba"

Thanks,  
Zhao Chun

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/386b9632-602d-44e2-9de7-de5bfbb5be18%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/386b9632-602d-44e2-9de7-de5bfbb5be18%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 1:49am UTC](https://discuss.elastic.co/t/how-to-do-a-subquery/15886/2 "2017-07-06T01:49:11Z")

</div>


