# Elastic search : Can query include kind of a subquery or subqueries using multiple indices?

**URL:** <https://discuss.elastic.co/t/elastic-search-can-query-include-kind-of-a-subquery-or-subqueries-using-multiple-indices/269443>\
**Category:** Elasticsearch\
**Created:** [April 7, 2021, 10:38am UTC](https://discuss.elastic.co/t/elastic-search-can-query-include-kind-of-a-subquery-or-subqueries-using-multiple-indices/269443 "2021-04-07T10:38:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vmanohar1](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@vmanohar1](https://discuss.elastic.co/u/vmanohar1)\
**Post date:** [April 7, 2021, 10:38am UTC](https://discuss.elastic.co/t/elastic-search-can-query-include-kind-of-a-subquery-or-subqueries-using-multiple-indices/269443/1 "2021-04-07T10:38:09Z")

</div>

- I have index1 with geo-point data, index2 with polygons. Index2 has multiple polygon rows for given say id value. I would like to find all geo-points from index1 that are inside any of the polygons from index2 having say id=1. Is it possible to do that in a single query?
- One way, I thought was - combine all polygon rows for each unique id value using multi-polgon(so that it becomes single row for each unique id) during data ingestion itself and then it is easy to do the intersection/within query using 2 indices. But there may be a better way of doing this.. If there is, can you please share that idea? Thanks.

---

<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:** [April 10, 2021, 5:44pm UTC](https://discuss.elastic.co/t/elastic-search-can-query-include-kind-of-a-subquery-or-subqueries-using-multiple-indices/269443/2 "2021-04-10T17:44:19Z")

</div>

> [@vmanohar1](#):
>
> I have index1 with geo-point data, index2 with polygons. Index2 has multiple polygon rows for given say id value. I would like to find all geo-points from index1 that are inside any of the polygons from index2 having say id=1. Is it possible to do that in a single query?

Elasticsearch does not support joins, so that is not possible.

> [@vmanohar1](#):
>
> One way, I thought was - combine all polygon rows for each unique id value using multi-polgon(so that it becomes single row for each unique id) during data ingestion itself and then it is easy to do the intersection/within query using 2 indices. But there may be a better way of doing this.. If there is, can you please share that idea? Thanks.

That is as far as I can tell still a join. You might be able to enrich at index time, but I can't see a way to do it in a single query.

---

<div class="post-metadata">

**Author:** ![vmanohar1](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@vmanohar1](https://discuss.elastic.co/u/vmanohar1)\
**Post date:** [April 11, 2021, 8:28pm UTC](https://discuss.elastic.co/t/elastic-search-can-query-include-kind-of-a-subquery-or-subqueries-using-multiple-indices/269443/3 "2021-04-11T20:28:00Z")

</div>

- Thanks for the feedback.. By enriching the data during ingestion, I was able to do it using the idea I mentioned earlier in the ticket.
- Ticket can be closed.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 12, 2021, 5:27am UTC](https://discuss.elastic.co/t/elastic-search-can-query-include-kind-of-a-subquery-or-subqueries-using-multiple-indices/269443/4 "2021-04-12T05:27:22Z")

</div>

> [@vmanohar1](#):
>
> - Ticket can be closed.

This is not a ticket system, this is a community technical support forum 🙂

---

<div class="post-metadata">

**Author:** ![vmanohar1](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@vmanohar1](https://discuss.elastic.co/u/vmanohar1)\
**Post date:** [April 12, 2021, 10:01am UTC](https://discuss.elastic.co/t/elastic-search-can-query-include-kind-of-a-subquery-or-subqueries-using-multiple-indices/269443/5 "2021-04-12T10:01:21Z")

</div>

- Yes. I forgot that. Thanks for reminding..

---

<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:** [May 10, 2021, 10:01am UTC](https://discuss.elastic.co/t/elastic-search-can-query-include-kind-of-a-subquery-or-subqueries-using-multiple-indices/269443/6 "2021-05-10T10:01:53Z")

</div>

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