# Does Elasticsearch provide an equivalent of IN (SELECT...)?

**URL:** <https://discuss.elastic.co/t/does-elasticsearch-provide-an-equivalent-of-in-select/317910>\
**Category:** Elasticsearch\
**Created:** [November 1, 2022, 4:16pm UTC](https://discuss.elastic.co/t/does-elasticsearch-provide-an-equivalent-of-in-select/317910 "2022-11-01T16:16:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luis95](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luis95/32/111142_2.png) [@Luis95](https://discuss.elastic.co/u/Luis95)\
**Post date:** [November 1, 2022, 4:16pm UTC](https://discuss.elastic.co/t/does-elasticsearch-provide-an-equivalent-of-in-select/317910/1 "2022-11-01T16:16:17Z")

</div>

We are saving one item for each user, show, and episode. We save everything on the same index.  
The ERD would look something like this:

```auto
 ┌────┐ ┌────────────┐ ┌────┐
 │User├─────<┤Subscription├>────┤Show│
 └────┘ └────────────┘ └─┬──┘
                                  │
                                  │
                                 /|\
                               ┌───────┐
                               │Episode│
                               └───────┘

```

And the items would look something like this:

User:

```auto
{ id: user-1, name: one }

```

Show:

```auto
{ id: show-1, title: showTitle }

```

Episode:

```auto
{ id: show-1, title: episodeTitle, showId: show-1, createdAt: today }

```

**We want to do a subscription page like youtube, we want to list all the episodes from all the shows the user has subscribed to.** If possible we would like to achieve this on a single query.

On PostgreSQL i would have used **IN** , with a query like this:

`SELECT * FROM Episode WHERE show_id IN (SELECT show_id FROM Subscription WHERE user_id = 'userId')`

Does ES provide a way to achieve this?  
We are thinking on using multiple queries, one for each subscription, but if possible we would like to delegate all this to a single Elasticsearch query.

---

<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 29, 2022, 4:16pm UTC](https://discuss.elastic.co/t/does-elasticsearch-provide-an-equivalent-of-in-select/317910/2 "2022-11-29T16:16:29Z")

</div>

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