# Custom preference key in searching

**URL:** <https://discuss.elastic.co/t/custom-preference-key-in-searching/219794>\
**Category:** Elasticsearch\
**Created:** [February 18, 2020, 1:29pm UTC](https://discuss.elastic.co/t/custom-preference-key-in-searching/219794 "2020-02-18T13:29:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Faiz\_Ahmed\_Mushtak\_H](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/faiz_ahmed_mushtak_h/32/47387_2.png) [@Faiz\_Ahmed\_Mushtak\_H](https://discuss.elastic.co/u/Faiz_Ahmed_Mushtak_H)\
**Post date:** [February 18, 2020, 1:29pm UTC](https://discuss.elastic.co/t/custom-preference-key-in-searching/219794/1 "2020-02-18T13:29:57Z")

</div>

When using a custom preference key in searches, ES ends up querying all the N shards of the index right? Surely out of N, few will be replicas, few will be primary

How does ES achieve this just using the string we pass? Does it store the preference in some cluster state for future reference so that same set of shards will be picked or is it computed in some deterministic manner (obviously)

Was going through [https://github.com/elastic/elasticsearch/blob/a4ed7b1ca102267ecdda7c788713675ed3958f3f/server/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java](https://github.com/elastic/elasticsearch/blob/a4ed7b1ca102267ecdda7c788713675ed3958f3f/server/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java)

but lost track of how shards are decided upon

---

<div class="post-metadata">

**Author:** ![Faiz\_Ahmed\_Mushtak\_H](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/faiz_ahmed_mushtak_h/32/47387_2.png) [@Faiz\_Ahmed\_Mushtak\_H](https://discuss.elastic.co/u/Faiz_Ahmed_Mushtak_H)\
**Post date:** [February 18, 2020, 1:37pm UTC](https://discuss.elastic.co/t/custom-preference-key-in-searching/219794/2 "2020-02-18T13:37:09Z")

</div>

Ok found out in `activeInitializingShardsIt`

The custom key is given as a seed which makes the shuffling in `activeInitializingShardsIt` deterministic

---

<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 17, 2020, 1:37pm UTC](https://discuss.elastic.co/t/custom-preference-key-in-searching/219794/3 "2020-03-17T13:37:11Z")

</div>

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