# Hashing algo. for Routing

**URL:** <https://discuss.elastic.co/t/hashing-algo-for-routing/13428>\
**Category:** Elasticsearch\
**Created:** [September 2, 2013, 7:41am UTC](https://discuss.elastic.co/t/hashing-algo-for-routing/13428 "2013-09-02T07:41:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anand\_Nalya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anand_nalya/32/571_2.png) [@Anand\_Nalya](https://discuss.elastic.co/u/Anand_Nalya)\
**Post date:** [September 2, 2013, 7:41am UTC](https://discuss.elastic.co/t/hashing-algo-for-routing/13428/1 "2013-09-02T07:41:11Z")

</div>

Hi,

I wanted to know which hashing algorithm is used by ES for sharding. I can  
find 2 in  
[https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/cluster/routing/operation/hash](https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/cluster/routing/operation/hash).

Also, is there a way of specifying a custom hashing algorithm? The problem  
I'm trying to solve is that the no. of routing keys that I have is around 2  
times the number of shards in the index and I want each shard to support  
two routing keys.

Thanks,  
Anand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [September 2, 2013, 4:06pm UTC](https://discuss.elastic.co/t/hashing-algo-for-routing/13428/2 "2013-09-02T16:06:51Z")

</div>

Hi,  
have a look at OperationRoutingModule[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/cluster/routing/operation/OperationRoutingModule.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/cluster/routing/operation/OperationRoutingModule.java)to find out more. That's the guice module that loads by default  
the DjbHashFunction. Never tried it myself but it looks like it's also  
possible to plug in a custom hash function that implements the HashFunction  
interface, using the cluster.routing.operation.hash.type setting.

Hope this helps  
Luca

On Monday, September 2, 2013 9:41:11 AM UTC+2, Anand Nalya wrote:

> Hi,
> 
> I wanted to know which hashing algorithm is used by ES for sharding. I can  
> find 2 in  
> [https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/cluster/routing/operation/hash](https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/cluster/routing/operation/hash)  
> .
> 
> Also, is there a way of specifying a custom hashing algorithm? The problem  
> I'm trying to solve is that the no. of routing keys that I have is around 2  
> times the number of shards in the index and I want each shard to support  
> two routing keys.
> 
> Thanks,  
> Anand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [September 11, 2013, 2:16pm UTC](https://discuss.elastic.co/t/hashing-algo-for-routing/13428/3 "2013-09-11T14:16:12Z")

</div>

Hi Anand,  
any news? Looking back at your question, I wonder why you need to write a  
custom hashing algorithm. Can't you just use custom routing? Would love to  
know more about your usecase.

Cheers  
Luca

On Monday, September 2, 2013 6:06:51 PM UTC+2, Luca Cavanna wrote:

> Hi,  
> have a look at OperationRoutingModule[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/cluster/routing/operation/OperationRoutingModule.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/cluster/routing/operation/OperationRoutingModule.java)to find out more. That's the guice module that loads by default  
> the DjbHashFunction. Never tried it myself but it looks like it's also  
> possible to plug in a custom hash function that implements the HashFunction  
> interface, using the cluster.routing.operation.hash.type setting.
> 
> Hope this helps  
> Luca
> 
> On Monday, September 2, 2013 9:41:11 AM UTC+2, Anand Nalya wrote:
> 
> > Hi,
> > 
> > I wanted to know which hashing algorithm is used by ES for sharding. I  
> > can find 2 in  
> > [https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/cluster/routing/operation/hash](https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/cluster/routing/operation/hash)  
> > .
> > 
> > Also, is there a way of specifying a custom hashing algorithm? The  
> > problem I'm trying to solve is that the no. of routing keys that I have is  
> > around 2 times the number of shards in the index and I want each shard to  
> > support two routing keys.
> > 
> > Thanks,  
> > Anand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Anand\_Nalya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anand_nalya/32/571_2.png) [@Anand\_Nalya](https://discuss.elastic.co/u/Anand_Nalya)\
**Post date:** [September 12, 2013, 4:48am UTC](https://discuss.elastic.co/t/hashing-algo-for-routing/13428/4 "2013-09-12T04:48:38Z")

</div>

Hi Luca,

My use case was to have completely predictable routing of documents at  
shard level. For example, I wanted to have the document with particular  
value of attribute a1 and a2 to go to shard0 and for some other combination  
to shard2.

To solve this, I did use a custom routing algorithm that gives a routing  
value from _A_ to _(A+noOfShards-1)_. In this way even though I cannot  
pinpoint the actual shard where the data goes, I can be sure that data  
with routing key k and k+1 goes to adjacent shards.

Anand

On Wednesday, 11 September 2013 19:46:12 UTC+5:30, Luca Cavanna wrote:

> Hi Anand,  
> any news? Looking back at your question, I wonder why you need to write a  
> custom hashing algorithm. Can't you just use custom routing? Would love to  
> know more about your usecase.
> 
> Cheers  
> Luca
> 
> On Monday, September 2, 2013 6:06:51 PM UTC+2, Luca Cavanna wrote:
> 
> > Hi,  
> > have a look at OperationRoutingModule[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/cluster/routing/operation/OperationRoutingModule.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/cluster/routing/operation/OperationRoutingModule.java)to find out more. That's the guice module that loads by default  
> > the DjbHashFunction. Never tried it myself but it looks like it's also  
> > possible to plug in a custom hash function that implements the HashFunction  
> > interface, using the cluster.routing.operation.hash.type setting.
> > 
> > Hope this helps  
> > Luca
> > 
> > On Monday, September 2, 2013 9:41:11 AM UTC+2, Anand Nalya wrote:
> > 
> > > Hi,
> > > 
> > > I wanted to know which hashing algorithm is used by ES for sharding. I  
> > > can find 2 in  
> > > [https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/cluster/routing/operation/hash](https://github.com/elasticsearch/elasticsearch/tree/master/src/main/java/org/elasticsearch/cluster/routing/operation/hash)  
> > > .
> > > 
> > > Also, is there a way of specifying a custom hashing algorithm? The  
> > > problem I'm trying to solve is that the no. of routing keys that I have is  
> > > around 2 times the number of shards in the index and I want each shard to  
> > > support two routing keys.
> > > 
> > > Thanks,  
> > > Anand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:17am UTC](https://discuss.elastic.co/t/hashing-algo-for-routing/13428/5 "2017-07-06T02:17:02Z")

</div>


