# Routing question

**URL:** <https://discuss.elastic.co/t/routing-question/10096>\
**Category:** Elasticsearch\
**Created:** [December 17, 2012, 4:28pm UTC](https://discuss.elastic.co/t/routing-question/10096 "2012-12-17T16:28:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ku3ia](https://avatars.discourse-cdn.com/v4/letter/k/c89c15/32.png) [@ku3ia](https://discuss.elastic.co/u/ku3ia)\
**Post date:** [December 17, 2012, 4:28pm UTC](https://discuss.elastic.co/t/routing-question/10096/1 "2012-12-17T16:28:50Z")

</div>

Hi all!

I'm newbie in elastic, please advice. I set up elastic v.0.19.11 on two VMs, summary I have 2 shards one on each VM. My mapping is:  
[http://10.112.1.10:9200/search/test/\_mapping/?pretty=true](http://10.112.1.10:9200/search/test/_mapping/?pretty=true)  
{  
"test" : {  
"\_all" : {  
"enabled" : false  
},  
"\_id" : {  
"path" : "RecordID"  
},  
"\_routing" : {  
"required" : true  
},  
"\_source" : {  
"enabled" : false  
},  
"properties" : {  
"Date" : {  
"type" : "date",  
"index" : "analyzed",  
"store" : "yes",  
"format" : "date\_time\_no\_millis"  
},  
"Name" : {  
"type" : "string",  
"analyzer" : "standard",  
"store" : "yes"  
},  
"RecordID" : {  
"type" : "string",  
"index" : "not\_analyzed",  
"store" : "yes"  
}  
}  
}  
}

I'm using bulk indexing with meta like {"index":{ "\_routing": 20121216 }} and {"index":{ "\_routing": 20121217 }}.  
My question is: when I run queries like  
[http://10.112.1.10:9200/search/test/\_search/?q=](http://10.112.1.10:9200/search/test/_search/?q=)_:_&fields=RecordID,\_routing&size=1&pretty=true&routing=20121217  
I get  
{  
"took" : 47,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 453184,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "search",  
"\_type" : "test",  
"\_id" : "16870466180",  
"\_score" : 1.0,  
"fields" : {  
"RecordID" : "16870466180",  
"\_routing" : "20121217"  
}  
} ]  
}  
}  
or  
[http://10.112.1.10:9200/search/test/\_search/?q=](http://10.112.1.10:9200/search/test/_search/?q=)_:_&fields=RecordID,\_routing&size=1&pretty=true&routing=20121216  
{  
"took" : 3,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "search",  
"\_type" : "test",  
"\_id" : "1",  
"\_score" : 1.0,  
"fields" : {  
"RecordID" : "1",  
"\_routing" : "20121216"  
}  
} ]  
}  
}  
seems looks fine. But when I tun, for example,  
[http://10.112.1.10:9200/search/test/\_search/?q=](http://10.112.1.10:9200/search/test/_search/?q=)_:_&fields=RecordID,\_routing&size=1&pretty=true&routing=abcd  
I get  
{  
"took" : 5,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 453184,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "search",  
"\_type" : "test",  
"\_id" : "16870466180",  
"\_score" : 1.0,  
"fields" : {  
"RecordID" : "16870466180",  
"\_routing" : "20121217"  
}  
} ]  
}  
}

Is it normal or I'm doing something wrong? Maybe this query mustn't return any results?

Thanks

---

<div class="post-metadata">

**Author:** ![andreasch](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@andreasch](https://discuss.elastic.co/u/andreasch)\
**Post date:** [December 17, 2012, 8:09pm UTC](https://discuss.elastic.co/t/routing-question/10096/2 "2012-12-17T20:09:11Z")

</div>

Dennis,

Routing values are used as hash values to determine which shard to store  
the document on.  
During the index operation, using the same routing therefore guarantees  
documents will always be placed on the same shard. However, 2 different  
routing do not necessarily reference 2 different shards.  
I would guess that "20121217" and "abcd" end up referencing the same shard.

As far as searching goes, search using routing does _NOT_ only return  
documents that were stored with the specified routing. It uses the  
specified routing to determine which shards to execute the search on.

See more information about search and routing here:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Since you search is open-ended, it returns all documents in the shard(s)  
associated with routing abcd (or 20121217).

Andreas

On Monday, December 17, 2012 9:28:50 AM UTC-7, dennis yermakov wrote:

> Hi all!
> 
> I'm newbie in elastic, please advice. I set up elastic v.0.19.11 on two  
> VMs,  
> summary I have 2 shards one on each VM. My mapping is:  
> [http://10.112.1.10:9200/search/test/\_mapping/?pretty=true](http://10.112.1.10:9200/search/test/_mapping/?pretty=true)  
> {  
> "test" : {  
> "\_all" : {  
> "enabled" : false  
> },  
> "\_id" : {  
> "path" : "RecordID"  
> },  
> "\_routing" : {  
> "required" : true  
> },  
> "\_source" : {  
> "enabled" : false  
> },  
> "properties" : {  
> "Date" : {  
> "type" : "date",  
> "index" : "analyzed",  
> "store" : "yes",  
> "format" : "date\_time\_no\_millis"  
> },  
> "Name" : {  
> "type" : "string",  
> "analyzer" : "standard",  
> "store" : "yes"  
> },  
> "RecordID" : {  
> "type" : "string",  
> "index" : "not\_analyzed",  
> "store" : "yes"  
> }  
> }  
> }  
> }
> 
> I'm using bulk indexing with meta like {"index":{ "\_routing": 20121216 }}  
> and {"index":{ "\_routing": 20121217 }}.  
> My question is: when I run queries like
> 
> [http://10.112.1.10:9200/search/test/\_search/?q=\*:\*&fields=RecordID,\_routing&size=1&pretty=true&routing=20121217](http://10.112.1.10:9200/search/test/_search/?q=*:*&fields=RecordID,_routing&size=1&pretty=true&routing=20121217)  
> I get  
> {  
> "took" : 47,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 453184,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "search",  
> "\_type" : "test",  
> "\_id" : "16870466180",  
> "\_score" : 1.0,  
> "fields" : {  
> "RecordID" : "16870466180",  
> "\_routing" : "20121217"  
> }  
> } ]  
> }  
> }  
> or
> 
> [http://10.112.1.10:9200/search/test/\_search/?q=\*:\*&fields=RecordID,\_routing&size=1&pretty=true&routing=20121216](http://10.112.1.10:9200/search/test/_search/?q=*:*&fields=RecordID,_routing&size=1&pretty=true&routing=20121216)  
> {  
> "took" : 3,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 1,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "search",  
> "\_type" : "test",  
> "\_id" : "1",  
> "\_score" : 1.0,  
> "fields" : {  
> "RecordID" : "1",  
> "\_routing" : "20121216"  
> }  
> } ]  
> }  
> }  
> seems looks fine. But when I tun, for example,
> 
> [http://10.112.1.10:9200/search/test/\_search/?q=\*:\*&fields=RecordID,\_routing&size=1&pretty=true&routing=abcd](http://10.112.1.10:9200/search/test/_search/?q=*:*&fields=RecordID,_routing&size=1&pretty=true&routing=abcd)  
> I get  
> {  
> "took" : 5,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 453184,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "search",  
> "\_type" : "test",  
> "\_id" : "16870466180",  
> "\_score" : 1.0,  
> "fields" : {  
> "RecordID" : "16870466180",  
> "\_routing" : "20121217"  
> }  
> } ]  
> }  
> }
> 
> Is it normal or I'm doing something wrong? Maybe this query mustn't return  
> any results?
> 
> Thanks
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Routing-question-tp4027080.html](http://elasticsearch-users.115913.n3.nabble.com/Routing-question-tp4027080.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--

---

<div class="post-metadata">

**Author:** ![ku3ia](https://avatars.discourse-cdn.com/v4/letter/k/c89c15/32.png) [@ku3ia](https://discuss.elastic.co/u/ku3ia)\
**Post date:** [December 18, 2012, 9:21am UTC](https://discuss.elastic.co/t/routing-question/10096/3 "2012-12-18T09:21:02Z")

</div>

andreasch, many thanks for your help! seems I understand how it works!

---

<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:59am UTC](https://discuss.elastic.co/t/routing-question/10096/4 "2017-07-06T02:59:28Z")

</div>


