# Nested queries (or secondary query)

**URL:** <https://discuss.elastic.co/t/nested-queries-or-secondary-query/296452>\
**Category:** Elasticsearch\
**Created:** [February 7, 2022, 10:21am UTC](https://discuss.elastic.co/t/nested-queries-or-secondary-query/296452 "2022-02-07T10:21:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eladf](https://avatars.discourse-cdn.com/v4/letter/e/df705f/32.png) [@eladf](https://discuss.elastic.co/u/eladf)\
**Post date:** [February 7, 2022, 10:21am UTC](https://discuss.elastic.co/t/nested-queries-or-secondary-query/296452/1 "2022-02-07T10:21:17Z")

</div>

Hi all,

I encountered an issue and will appreciate your help with it.  
I have a huge index (~0.5B documents) with a mapping that includes numeric fields (enum values), one keyword field and a nested field.  
The nested field includes and array of textual data (text fields) - can reach MBs of data.

I want to query the index in the following order:

1. First filter out only the items that have specific enum values (reduce the number of optional results from 0.5B to much reasonable number) - should usually reduce the items to 10K - 100K
2. Then go over the remained items and filter out only the relevant items which the nested items include.

I tried the nested query, as I understood it should perform some kind of a join between the two queries (regular and nested objects), however it doesn't reduce the response times.

My questions are:

1. What am I doing wrong?
2. Is it even possible in elastic?

Thanks in advance,  
Elad.

---

<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:** [March 7, 2022, 10:21am UTC](https://discuss.elastic.co/t/nested-queries-or-secondary-query/296452/2 "2022-03-07T10:21:55Z")

</div>

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