# What does it mean a shard executing a search locally?

**URL:** <https://discuss.elastic.co/t/what-does-it-mean-a-shard-executing-a-search-locally/342298>\
**Category:** Elasticsearch\
**Created:** [September 5, 2023, 3:07am UTC](https://discuss.elastic.co/t/what-does-it-mean-a-shard-executing-a-search-locally/342298 "2023-09-05T03:07:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dhineshkumar\_R](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dhineshkumar_r/32/122038_2.png) [@Dhineshkumar\_R](https://discuss.elastic.co/u/Dhineshkumar_R)\
**Post date:** [September 5, 2023, 3:07am UTC](https://discuss.elastic.co/t/what-does-it-mean-a-shard-executing-a-search-locally/342298/1 "2023-09-05T03:07:19Z")

</div>

Hi Folks,

I need some help understanding [Query phase](https://www.elastic.co/guide/en/elasticsearch/guide/current/_query_phase.html) of distributed search in ES better, step 2 specifically.

> 1. `Node 3` forwards the search request to a primary or replica copy of every shard in the index. Each shard executes the query locally and adds the results into a local sorted priority queue of size `from + size`.

I understand that each Node in the cluster has task specific thread pools to perform a task. Coordinating node accepts client request with one thread from search thread-pool. Similarly, when one of the data node receives a search request from coordinating node, one thread from it's search thread pool is utilized.

What does it mean each Shards executes the query locally mean? Does each shard have their own threads to perform the search? Currently, I imagine Shards as a block of storage space within it are Segments. The thread(T1) selected to handle the search request in the data node performs the search concurrently based on the `max_concurrent_shard_requests` parameter. After multiple concurrent searches, T1 aggregates the result in a priority queue and sends it back to coordinating node.

I think I don't fully understand the connection between a Shard and the CPUs. If there is any, please help me understand. Also, please correct me if I misunderstood any other part in my explanation.

Thanks much

---

<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:** [September 5, 2023, 4:31am UTC](https://discuss.elastic.co/t/what-does-it-mean-a-shard-executing-a-search-locally/342298/2 "2023-09-05T04:31:17Z")

</div>

> [@Dhineshkumar\_R](#):
>
> Does each shard have their own threads to perform the search?

No. There is a thread pool on the node performing the shard query and the task is queued up there and executed by the threadpool. I believe the `max_concurrent_shard_requests` parameter simply restricts how many shard search requests that are concurrently sent to a single node, so all shard search requests are not necessarily sent out at exacly the same time.

---

<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:** [October 3, 2023, 4:31am UTC](https://discuss.elastic.co/t/what-does-it-mean-a-shard-executing-a-search-locally/342298/3 "2023-10-03T04:31:57Z")

</div>

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