# Routing on multiple fields

**URL:** <https://discuss.elastic.co/t/routing-on-multiple-fields/6701>\
**Category:** Elasticsearch\
**Created:** [February 14, 2012, 8:26am UTC](https://discuss.elastic.co/t/routing-on-multiple-fields/6701 "2012-02-14T08:26:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ridvan\_Gyundogan](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@Ridvan\_Gyundogan](https://discuss.elastic.co/u/Ridvan_Gyundogan)\
**Post date:** [February 14, 2012, 8:26am UTC](https://discuss.elastic.co/t/routing-on-multiple-fields/6701/1 "2012-02-14T08:26:32Z")

</div>

Hi I have the following scenario and I need some help with the  
routing.  
my documents have the following structure  
Doc{  
userId:String  
username:String  
.....  
}

When indexing I always have userId, sometimes I have username.

When searching I have userId or username or both. The relation userId  
to username is M:1 , several userIds can belong to the same username,  
don't ask me why 😉

I want to use the benefits of routing when searching which looks  
possible in my scenario.

I was thinking to index based on routing on userId .  
When the search contains userid - it is all fine.  
When the search contains only username though I need to specify all  
the userids belonging to the specific username. So for this I need  
another search request to find the username's userids.

Any idea how to avoid this extra request for finding username's  
userids?

---

<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, 3:39am UTC](https://discuss.elastic.co/t/routing-on-multiple-fields/6701/2 "2017-07-06T03:39:30Z")

</div>


