# Elastic search coordinating-node role - complex aggregations

**URL:** <https://discuss.elastic.co/t/elastic-search-coordinating-node-role-complex-aggregations/225622>\
**Category:** Elasticsearch\
**Created:** [March 30, 2020, 7:29am UTC](https://discuss.elastic.co/t/elastic-search-coordinating-node-role-complex-aggregations/225622 "2020-03-30T07:29:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nages](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nages/32/46943_2.png) [@nages](https://discuss.elastic.co/u/nages)\
**Post date:** [March 30, 2020, 7:29am UTC](https://discuss.elastic.co/t/elastic-search-coordinating-node-role-complex-aggregations/225622/1 "2020-03-30T07:29:48Z")

</div>

I understood coordinate node broadcasts the search request and gathers the results received from data nodes using "query then fetch phase" .

Does it do it in one iteration of "query then fetch phase" or a search request can have multiple iterations of query then fetch phases?

Say taking a complex filter query taken from [Elastic Search Complex Scenario](https://stackoverflow.com/questions/32257888/elastic-search-complex-scenario) (credits : Val, Thanks @Val), will it involve multiple iterations of query then fetch phases? what are the steps the coordinating node does to answer this query

```auto
{
  "query": {
    "filtered": {
      "query": {
        "match": {
          "product_name": "xxx"
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "range": {
                "price": {
                  "gte": 20,
                  "lte": 170
                }
              }
            },
            {
              "term": {
                "availability": "availability_status"
              }
            },
            {
              "term": {
                "user": 1
              }
            }
          ]
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [March 30, 2020, 9:20am UTC](https://discuss.elastic.co/t/elastic-search-coordinating-node-role-complex-aggregations/225622/2 "2020-03-30T09:20:30Z")

</div>

Hi nages,  
The complexity of a query doesn't increase the number of phases.

There can be some pre-flight visits to test if a query can match at all on a shard (e.g. it might not have any of the required fields) or stats-gathering for special scoring modes ([DFS](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#dfs-query-then-fetch)).

None of these decisions are influenced by the complexity of your query though - this requires a one-time pass over the data.

---

<div class="post-metadata">

**Author:** ![nages](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nages/32/46943_2.png) [@nages](https://discuss.elastic.co/u/nages)\
**Post date:** [March 30, 2020, 10:21am UTC](https://discuss.elastic.co/t/elastic-search-coordinating-node-role-complex-aggregations/225622/3 "2020-03-30T10:21:52Z")

</div>

It seems like elastic search address most(if not all) of the queries using one iteration of Query then fetch . Am I right ? Would you sharing document , i went through the online documentation , but didnt get a correct picture.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [March 31, 2020, 9:32am UTC](https://discuss.elastic.co/t/elastic-search-coordinating-node-role-complex-aggregations/225622/4 "2020-03-31T09:32:28Z")

</div>

> [@nages](#):
>
> Am I right ?

Yes. The phases are discussed [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-search-type).

---

<div class="post-metadata">

**Author:** ![nages](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nages/32/46943_2.png) [@nages](https://discuss.elastic.co/u/nages)\
**Post date:** [March 31, 2020, 10:15am UTC](https://discuss.elastic.co/t/elastic-search-coordinating-node-role-complex-aggregations/225622/5 "2020-03-31T10:15:31Z")

</div>

thanks Mark, I went through the document earlier but seems like many details were abstract like pre flight visits , plan etc 🙂 . Perhaps, i may need to look at the source code..

Thanks anyways

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [March 31, 2020, 10:27am UTC](https://discuss.elastic.co/t/elastic-search-coordinating-node-role-complex-aggregations/225622/6 "2020-03-31T10:27:06Z")

</div>

The details change as various things are optimised and evolve.  
There are a number of "it depends" e.g. the "canMatch" pre-flight phase will not run if there's insufficient numbers of shards being queried or custom search routing is used or DFS is used.  
Cross-cluster-search is another consideration.

[Here's](https://github.com/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java#L543) probably a good place to start if you're curious.

---

<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:** [April 28, 2020, 10:27am UTC](https://discuss.elastic.co/t/elastic-search-coordinating-node-role-complex-aggregations/225622/7 "2020-04-28T10:27:07Z")

</div>

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