# General question about field routing

**URL:** <https://discuss.elastic.co/t/general-question-about-field-routing/9310>\
**Category:** Elasticsearch\
**Created:** [October 10, 2012, 8:02pm UTC](https://discuss.elastic.co/t/general-question-about-field-routing/9310 "2012-10-10T20:02:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yuhan](https://avatars.discourse-cdn.com/v4/letter/y/919ad9/32.png) [@Yuhan](https://discuss.elastic.co/u/Yuhan)\
**Post date:** [October 10, 2012, 8:02pm UTC](https://discuss.elastic.co/t/general-question-about-field-routing/9310/1 "2012-10-10T20:02:58Z")

</div>

Hi all,

Is field routing smart enough to set the routing from a query string if the  
routing field is presented?  
or I have to explicit adding the routing parameter?

Thank you.

Yuhan

--

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [October 11, 2012, 7:47am UTC](https://discuss.elastic.co/t/general-question-about-field-routing/9310/2 "2012-10-11T07:47:15Z")

</div>

On Wed, 2012-10-10 at 13:02 -0700, Yuhan Zhang wrote:

> Hi all,
> 
> Is field routing smart enough to set the routing from a query string  
> if the routing field is presented?  
> or I have to explicit adding the routing parameter?

I think you need to be more explicit in your question 🙂

clint

--

---

<div class="post-metadata">

**Author:** ![Yuhan](https://avatars.discourse-cdn.com/v4/letter/y/919ad9/32.png) [@Yuhan](https://discuss.elastic.co/u/Yuhan)\
**Post date:** [October 11, 2012, 6:04pm UTC](https://discuss.elastic.co/t/general-question-about-field-routing/9310/3 "2012-10-11T18:04:49Z")

</div>

Hi Clinton,

I'd like to use index with routing, but wondering whether the code in  
application level need to be updated to include the routing parameter.

I have set up field routing on a field called "account\_id", and was able  
to search with routing parameters to reach only 1 shard:

[http://localhost:9200/videos/\_search?routing=123&q=](http://localhost:9200/videos/_search?routing=123&q=)\*

The existing code consists various queries with account\_id provided.  
ex:  
[http://localhost:9200/videos/\_search?q=account\_id:123+AND+text:test](http://localhost:9200/videos/_search?q=account_id:123+AND+text:test)

So, will elasticsearch smartly reach just 1 shard on this query? or will it  
still reach all shards?

Thank you.

Yuhan

On Thu, Oct 11, 2012 at 12:47 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:

> On Wed, 2012-10-10 at 13:02 -0700, Yuhan Zhang wrote:
> 
> > Hi all,
> > 
> > Is field routing smart enough to set the routing from a query string  
> > if the routing field is presented?  
> > or I have to explicit adding the routing parameter?
> 
> I think you need to be more explicit in your question 🙂
> 
> clint
> 
> --

--

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [October 12, 2012, 9:37am UTC](https://discuss.elastic.co/t/general-question-about-field-routing/9310/4 "2012-10-12T09:37:28Z")

</div>

Hi Yuhan

> The existing code consists various queries with account\_id provided.  
> ex:  
> [http://localhost:9200/videos/\_search?q=account\_id:123+AND+text:test](http://localhost:9200/videos/_search?q=account_id:123+AND+text:test)
> 
> So, will elasticsearch smartly reach just 1 shard on this query? or  
> will it still reach all shards?

Ah right. Not sure, but I think the answer is probably no. It won't do  
that automatically. You'll still need to provide the routing value.

Maybe it could be supported. Perhaps open an issue.

clint

--

---

<div class="post-metadata">

**Author:** ![Yuhan](https://avatars.discourse-cdn.com/v4/letter/y/919ad9/32.png) [@Yuhan](https://discuss.elastic.co/u/Yuhan)\
**Post date:** [October 13, 2012, 1:44am UTC](https://discuss.elastic.co/t/general-question-about-field-routing/9310/5 "2012-10-13T01:44:25Z")

</div>

Hi thanks Clinton, I opened an issue:

> <https://github.com/elastic/elasticsearch/issues/2325>
>
> Currently field routing will route a record to a row during the indexing phase. …However, when we are querying it, it expects the user to provide the routing= parameter, ignoring the field appearing in the query. if no routing parameter, the request will reach all shards.
> 
> Please improve the field routing feature to automatically detect the routing number from the query such that if the field value appeared in the query, automatically take that value as the routing key.
> 
> Example:
> 
> we have a index "videos" defined with routing on "account\_id" field:
> "videos": {
> "\_routing": {
> "required": true,
> "path": "account\_id"
> },
> "properties": {
> "account\_id": {
> "type": "integer",
> "ignore\_malformed": false
> },
> "text": {
> "type": "string",
> "analyzer": "simple"
> },
> ...
> 
> The two queries given different performance (measured through apache bench):
> - http://localhost:9200/videos/\_search?q=account\_id:1001560%20and%20text:vampire
> - http://localhost:9200/videos/\_search?q=account\_id:1001560%20and%20text:vampire&routing=1001560
> 
> Make it such that if account\_id field appears in query, it automatically assign it as routing (so that no need to update it at application level. )
> 
> Thank you.
> 
> request based on the discussion from the mailing list:
> 
> Hi Yuhan
> 
> \> The existing code consists various queries with account\_id provided.
> \> ex:
> \> http://localhost:9200/videos/\_search?q=account\_id:123+AND+text:test
> \> 
> \> So, will elasticsearch smartly reach just 1 shard on this query? or
> \> will it still reach all shards?
> 
> Ah right. Not sure, but I think the answer is probably no. It won't do
> that automatically. You'll still need to provide the routing value.
> 
> Maybe it could be supported. Perhaps open an issue.
> 
> clint

verified from apache bench that provided with routing, it is 3 times  
faster. so this feature indeed is missing..

Thank you.

Yuhan

On Fri, Oct 12, 2012 at 2:37 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:

> Hi Yuhan
> 
> > The existing code consists various queries with account\_id provided.  
> > ex:  
> > [http://localhost:9200/videos/\_search?q=account\_id:123+AND+text:test](http://localhost:9200/videos/_search?q=account_id:123+AND+text:test)
> > 
> > So, will elasticsearch smartly reach just 1 shard on this query? or  
> > will it still reach all shards?
> 
> Ah right. Not sure, but I think the answer is probably no. It won't do  
> that automatically. You'll still need to provide the routing value.
> 
> Maybe it could be supported. Perhaps open an issue.
> 
> clint
> 
> --

--

---

<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:09am UTC](https://discuss.elastic.co/t/general-question-about-field-routing/9310/6 "2017-07-06T03:09:00Z")

</div>


