# Requests Containing an Array of Custom Routing Values

**URL:** <https://discuss.elastic.co/t/requests-containing-an-array-of-custom-routing-values/159435>\
**Category:** Elasticsearch\
**Created:** [December 5, 2018, 12:36am UTC](https://discuss.elastic.co/t/requests-containing-an-array-of-custom-routing-values/159435 "2018-12-05T00:36:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chinmaya\_Poswalia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chinmaya_poswalia/32/34395_2.png) [@Chinmaya\_Poswalia](https://discuss.elastic.co/u/Chinmaya_Poswalia)\
**Post date:** [December 5, 2018, 12:36am UTC](https://discuss.elastic.co/t/requests-containing-an-array-of-custom-routing-values/159435/1 "2018-12-05T00:36:01Z")

</div>

Hi Guys,  
We have a cluster partitioned by a certain key for which we are using custom routing. We now are having a use-case where we have to request data across different key with the key list to be large. So wanted to understand how is the custom routing query processed? I know when we specify a list of routing keys, elastic search goes to all the shards mapping those sets of routing keys and fetches the data. I have a couple of questions around that

- Lets say the custom routing parameter array contains 1000 values. There are only 10 shards though. Will there be 1000 request internally with one for each routing or at max there will be 10 request with one request per shard.
- When returning data with query containing multiple routing values, does elasticsearch paginate the requests (sort request across all partitions) and return the requested page or it returns data partitioned by routing key.

---

<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:** [December 5, 2018, 12:41am UTC](https://discuss.elastic.co/t/requests-containing-an-array-of-custom-routing-values/159435/2 "2018-12-05T00:41:18Z")

</div>

> [@Chinmaya\_Poswalia](#):
>
> Hi Guys,

We aren't all guys 🙂

> [@Chinmaya\_Poswalia](#):
>
> Lets say the custom routing parameter array contains 1000 values. There are only 10 shards though. Will there be 1000 request internally with one for each routing or at max there will be 10 request with one request per shard.

Requests are sent per shard. So you essentially end up with one bulk request with 100 individual requests per shard.

> [@Chinmaya\_Poswalia](#):
>
> When returning data with query containing multiple routing values, does elasticsearch paginate the requests (sort request across all partitions) and return the requested page or it returns data partitioned by routing key.

Elasticsearch will just look at it as one response, irrespective of the routing. I don't know if there is a way to change that though.

---

<div class="post-metadata">

**Author:** ![Chinmaya\_Poswalia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chinmaya_poswalia/32/34395_2.png) [@Chinmaya\_Poswalia](https://discuss.elastic.co/u/Chinmaya_Poswalia)\
**Post date:** [December 5, 2018, 12:57am UTC](https://discuss.elastic.co/t/requests-containing-an-array-of-custom-routing-values/159435/3 "2018-12-05T00:57:58Z")

</div>

Thanks @warkolm for your response.

> [@warkolm](#):
>
> We aren't all guys 🙂
> 
> ![](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chinmaya_poswalia/40/34395_1.png) Chinmaya\_Poswalia:

My sincere apologies

> [@warkolm](#):
>
> Elasticsearch will just look at it as one response, irrespective of the routing. I don't know if there is a way to change that though.

So in the above example assuming that the expected response to be top 25 records

- The co-ordinating shard will query all the 10 shards with each one returning 25 records.
- Then the co-ordinating shard will sort the 250 records and return the top 25 of them.  
Is the above flow correct?

---

<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:** [December 5, 2018, 1:13am UTC](https://discuss.elastic.co/t/requests-containing-an-array-of-custom-routing-values/159435/4 "2018-12-05T01:13:44Z")

</div>

Yes, it's the same as any other query.

---

<div class="post-metadata">

**Author:** ![Chinmaya\_Poswalia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chinmaya_poswalia/32/34395_2.png) [@Chinmaya\_Poswalia](https://discuss.elastic.co/u/Chinmaya_Poswalia)\
**Post date:** [December 5, 2018, 2:49am UTC](https://discuss.elastic.co/t/requests-containing-an-array-of-custom-routing-values/159435/5 "2018-12-05T02:49:44Z")

</div>

Is there a way to specify in the query to tell final shard to query and filter for only the list of values that it was resolved to based on the custom routing provided.

For example, lets say the cluster is partitioned by attribute A which is also present in the document.

- We have a query to get the top 25 documents where document's attribute A value should be among (A1, A2, .... A50).
- We have 10 shards such that shard S1 contains A1.. A5 and shard S2 contains A6 to A10 and so on.

Is there a way to query such that

- Shard S1 queries for A1 to A5 in its index and not from A6 to A50. Similarly S2 queries only for A6 to A10 and so on.  
This way shard S1 doesn't need to processes values that it doesn't contain and serves the query faster.

---

<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:** [December 5, 2018, 3:08am UTC](https://discuss.elastic.co/t/requests-containing-an-array-of-custom-routing-values/159435/6 "2018-12-05T03:08:18Z")

</div>

If you want to do that then you should use filters, that way it will use bitsets which are super efficient.

---

<div class="post-metadata">

**Author:** ![Chinmaya\_Poswalia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chinmaya_poswalia/32/34395_2.png) [@Chinmaya\_Poswalia](https://discuss.elastic.co/u/Chinmaya_Poswalia)\
**Post date:** [December 5, 2018, 3:54am UTC](https://discuss.elastic.co/t/requests-containing-an-array-of-custom-routing-values/159435/7 "2018-12-05T03:54:05Z")

</div>

> [@warkolm](#):
>
> If you want to do that then you should use filters, that way it will use bitsets which are super efficient.

Did you mean [Bool Query | Elasticsearch Guide [6.5] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/6.5/query-dsl-bool-query.html)  
or [Terms query | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html)

Couldn't find any documentation stating terms supported under filter?

---

<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:** [January 2, 2019, 3:54am UTC](https://discuss.elastic.co/t/requests-containing-an-array-of-custom-routing-values/159435/8 "2019-01-02T03:54:09Z")

</div>

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