# Output of where clause to use as filter

**URL:** https://discuss.elastic.co/t/output-of-where-clause-to-use-as-filter/39949
**Category:** Elasticsearch
**Created:** [January 23, 2016, 12:54pm UTC](https://discuss.elastic.co/t/output-of-where-clause-to-use-as-filter/39949 "2016-01-23T12:54:35Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jiteshanand](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@jiteshanand](https://discuss.elastic.co/u/jiteshanand)
#### Post date: [January 23, 2016, 12:54pm UTC](https://discuss.elastic.co/t/output-of-where-clause-to-use-as-filter/39949/1 "2016-01-23T12:54:35Z")

</div>

Hi,

I am new to ES and trying to build a query.  
I have tried 5-6 options but not getting desired result.Just want to make sure whether joins can be achieved in ES.Thanks for help.

# SQL will be like this

select symbol from stocks where stocks.industry == (select industry from stocks where symbol == 'XYZ')

I will be passing symbol at run time.

Thanks,  
Jitesh

---

<div class="post-metadata">

### Author: ![jiteshanand](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@jiteshanand](https://discuss.elastic.co/u/jiteshanand)
#### Post date: [January 23, 2016, 3:47pm UTC](https://discuss.elastic.co/t/output-of-where-clause-to-use-as-filter/39949/2 "2016-01-23T15:47:07Z")

</div>

Can someone please have a look and confirm whether this is possible or not using ES.

If yes,Please help.Otherwise I will explore other options.

Thanks,  
Jitesh

---

<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: [January 23, 2016, 4:01pm UTC](https://discuss.elastic.co/t/output-of-where-clause-to-use-as-filter/39949/3 "2016-01-23T16:01:45Z")

</div>

That will as far as I can tell require 2 separate queries in Elasticsearch.

---

<div class="post-metadata">

### Author: ![jiteshanand](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@jiteshanand](https://discuss.elastic.co/u/jiteshanand)
#### Post date: [January 23, 2016, 4:05pm UTC](https://discuss.elastic.co/t/output-of-where-clause-to-use-as-filter/39949/4 "2016-01-23T16:05:03Z")

</div>

Thanks a lot for replying.

2 queries means one to get first result and then ask server again to send other result using first output.?  
I am trying to have less number of request to server.

Thanks,  
Jitesh

---

<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: [January 23, 2016, 4:13pm UTC](https://discuss.elastic.co/t/output-of-where-clause-to-use-as-filter/39949/5 "2016-01-23T16:13:59Z")

</div>

Exactly. Elasticsearch does not support joins, so you can not feed the results from one query into another in one request.

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [January 24, 2016, 7:55pm UTC](https://discuss.elastic.co/t/output-of-where-clause-to-use-as-filter/39949/6 "2016-01-24T19:55:28Z")

</div>

There is lookup support for the terms query iirc which makes it like a  
fairly weak, single layer join.

---

<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 5, 2017, 11:22pm UTC](https://discuss.elastic.co/t/output-of-where-clause-to-use-as-filter/39949/7 "2017-07-05T23:22:04Z")

</div>


