# Routing does not work for me

**URL:** <https://discuss.elastic.co/t/routing-does-not-work-for-me/7766>\
**Category:** Elasticsearch\
**Created:** [May 18, 2012, 6:21pm UTC](https://discuss.elastic.co/t/routing-does-not-work-for-me/7766 "2012-05-18T18:21:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![arta](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@arta](https://discuss.elastic.co/u/arta)\
**Post date:** [May 18, 2012, 6:21pm UTC](https://discuss.elastic.co/t/routing-does-not-work-for-me/7766/1 "2012-05-18T18:21:31Z")

</div>

(Google Group keeps deleting my posts, so I try here.)  
Hi,  
I'm experimenting routing but having difficulties. Please help.  
My observation is that documents that have the same routing value are indexed in different shards.  
Here's the outline.

- in the _default_ mapping, I set a routing field "rt".
- indexed 3 docs in /test/type1 with routing value "rt1".
- indexed 4 docs in /test/type2 with routing value "rt2".
- indexed 1 doc in /test/type3 with routing value "rt3".
- GET /test/\_status returns all 8 docs, but shard0 has 2 docs, shard1 has 3 docs, shard2 has 3 docs.
- the distribution does not match the intention.
- GET /test/\_search?q=\* returns all 8 docs
- GET /test/\_search?q=\*&routing=rt1 returns only 2 docs - supposed to be 3 docs
- GET /test/\_search?q=\*&routing=rt2 returns only 3 docs - supposed to be 4 docs
- GET /test/\_search?q=\*&routing=rt3 returns 3 docs - supposed to be 1 doc

Please let me know what I'm doing wrong.  
Thanks for your help.

Here's detail:  
curl -XDELETE '[http://localhost:9200/test](http://localhost:9200/test)'  
curl -XPUT '[http://localhost:9200/test](http://localhost:9200/test)' -d '{"settings":{"number\_of\_shards":5,"number\_of\_replicas":0},"mappings":{"_default_":{"\_routing":{"path":"rt"}}}}'

curl -XPUT '[http://localhost:9200/test/type1/1](http://localhost:9200/test/type1/1)' -d '{"file":"type1-1.txt","rt":"rt1"}'  
curl -XPUT '[http://localhost:9200/test/type1/2](http://localhost:9200/test/type1/2)' -d '{"file":"type1-2.txt","rt":"rt1"}'  
curl -XPUT '[http://localhost:9200/test/type1/3](http://localhost:9200/test/type1/3)' -d '{"file":"type1-3.txt","rt":"rt1"}'  
curl -XPUT '[http://localhost:9200/test/type2/1](http://localhost:9200/test/type2/1)' -d '{"file":"type2-1.txt","rt":"rt2"}'  
curl -XPUT '[http://localhost:9200/test/type2/2](http://localhost:9200/test/type2/2)' -d '{"file":"type2-2.txt","rt":"rt2"}'  
curl -XPUT '[http://localhost:9200/test/type2/3](http://localhost:9200/test/type2/3)' -d '{"file":"type2-3.txt","rt":"rt2"}'  
curl -XPUT '[http://localhost:9200/test/type2/4](http://localhost:9200/test/type2/4)' -d '{"file":"type2-4.txt","rt":"rt2"}'  
curl -XPUT '[http://localhost:9200/test/type3/1](http://localhost:9200/test/type3/1)' -d '{"file":"type3-1.txt","rt":"rt3"}'

- GET /test/\_status returns all 8 docs, but shard0 has 2 docs, shard1 has 3 docs, shard2 has 3 docs.
- the distribution does not match the intention.

curl -XGET '[http://localhost:9200/test/\_status?pretty=true](http://localhost:9200/test/_status?pretty=true)'  
{  
"ok" : true,  
"\_shards" : {  
"total" : 5,   
"indices" : {   
"shards" : {  
"0" : [ {   
"docs" : {  
"num\_docs" : 2,   
"1" : [ {   
"docs" : {  
"num\_docs" : 3,   
"2" : [ {   
"docs" : {  
"num\_docs" : 3,   
"3" : [ {   
"docs" : {  
"num\_docs" : 0,   
"4" : [ {   
"docs" : {  
"num\_docs" : 0,

- GET /test/\_search?q=\* returns all 8 docs

curl '[http://localhost:9200/test/\_search?q=\*&size=10&pretty=true](http://localhost:9200/test/_search?q=*&size=10&pretty=true)'  
{  
"took" : 84,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 8,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "test",  
"\_type" : "type1",  
"\_id" : "2",  
"\_score" : 1.0, "\_source" : {"file":"type1-2.txt","rt":"rt1"}  
}, {  
"\_index" : "test",  
"\_type" : "type1",  
"\_id" : "3",  
"\_score" : 1.0, "\_source" : {"file":"type1-3.txt","rt":"rt1"}  
}, {  
"\_index" : "test",  
"\_type" : "type2",  
"\_id" : "2",  
"\_score" : 1.0, "\_source" : {"file":"type2-2.txt","rt":"rt2"}  
}, {  
"\_index" : "test",  
"\_type" : "type2",  
"\_id" : "3",  
"\_score" : 1.0, "\_source" : {"file":"type2-3.txt","rt":"rt2"}  
}, {  
"\_index" : "test",  
"\_type" : "type2",  
"\_id" : "4",  
"\_score" : 1.0, "\_source" : {"file":"type2-4.txt","rt":"rt2"}  
}, {  
"\_index" : "test",  
"\_type" : "type1",  
"\_id" : "1",  
"\_score" : 1.0, "\_source" : {"file":"type1-1.txt","rt":"rt1"}  
}, {  
"\_index" : "test",  
"\_type" : "type2",  
"\_id" : "1",  
"\_score" : 1.0, "\_source" : {"file":"type2-1.txt","rt":"rt2"}  
}, {  
"\_index" : "test",  
"\_type" : "type3",  
"\_id" : "1",  
"\_score" : 1.0, "\_source" : {"file":"type3-1.txt","rt":"rt3"}  
} ]  
}  
}

- GET /test/\_search?q=\*&routing=rt1 returns only 2 docs - supposed to be 3 docs

curl '[http://localhost:9200/test/\_search?q=\*&size=10&pretty=true&routing=rt1](http://localhost:9200/test/_search?q=*&size=10&pretty=true&routing=rt1)'  
{  
"took" : 1,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 2,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "test",  
"\_type" : "type1",  
"\_id" : "2",  
"\_score" : 1.0, "\_source" : {"file":"type1-2.txt","rt":"rt1"}  
}, {  
"\_index" : "test",  
"\_type" : "type1",  
"\_id" : "3",  
"\_score" : 1.0, "\_source" : {"file":"type1-3.txt","rt":"rt1"}  
} ]  
}  
}

- GET /test/\_search?q=\*&routing=rt2 returns only 3 docs - supposed to be 4 docs

curl '[http://localhost:9200/test/\_search?q=\*&size=10&pretty=true&routing=rt2](http://localhost:9200/test/_search?q=*&size=10&pretty=true&routing=rt2)'  
{  
"took" : 2,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 3,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "test",  
"\_type" : "type2",  
"\_id" : "2",  
"\_score" : 1.0, "\_source" : {"file":"type2-2.txt","rt":"rt2"}  
}, {  
"\_index" : "test",  
"\_type" : "type2",  
"\_id" : "3",  
"\_score" : 1.0, "\_source" : {"file":"type2-3.txt","rt":"rt2"}  
}, {  
"\_index" : "test",  
"\_type" : "type2",  
"\_id" : "4",  
"\_score" : 1.0, "\_source" : {"file":"type2-4.txt","rt":"rt2"}  
} ]  
}  
}

- GET /test/\_search?q=\*&routing=rt3 returns 3 docs - supposed to be 1 doc

curl '[http://localhost:9200/test/\_search?q=\*&size=10&pretty=true&routing=rt3](http://localhost:9200/test/_search?q=*&size=10&pretty=true&routing=rt3)'  
{  
"took" : 2,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"hits" : {  
"total" : 3,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "test",  
"\_type" : "type1",  
"\_id" : "1",  
"\_score" : 1.0, "\_source" : {"file":"type1-1.txt","rt":"rt1"}  
}, {  
"\_index" : "test",  
"\_type" : "type2",  
"\_id" : "1",  
"\_score" : 1.0, "\_source" : {"file":"type2-1.txt","rt":"rt2"}  
}, {  
"\_index" : "test",  
"\_type" : "type3",  
"\_id" : "1",  
"\_score" : 1.0, "\_source" : {"file":"type3-1.txt","rt":"rt3"}  
} ]  
}  
}

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 20, 2012, 8:30pm UTC](https://discuss.elastic.co/t/routing-does-not-work-for-me/7766/2 "2012-05-20T20:30:47Z")

</div>

I answered on another same thread, and saw several of those messages in the  
spam folder of the google group just now. Not sure why it decided that the  
messages were spam...

On Fri, May 18, 2012 at 8:21 PM, arta [artasano@sbcglobal.net](mailto:artasano@sbcglobal.net) wrote:

> (Google Group keeps deleting my posts, so I try here.)  
> Hi,  
> I'm experimenting routing but having difficulties. Please help.  
> My observation is that documents that have the same routing value are  
> indexed in different shards.  
> Here's the outline.
> 
> - in the _default_ mapping, I set a routing field "rt".
> - indexed 3 docs in /test/type1 with routing value "rt1".
> - indexed 4 docs in /test/type2 with routing value "rt2".
> - indexed 1 doc in /test/type3 with routing value "rt3".
> - GET /test/\_status returns all 8 docs, but shard0 has 2 docs, shard1 has 3  
> docs, shard2 has 3 docs.
> - the distribution does not match the intention.
> - GET /test/\_search?q=\* returns all 8 docs
> - GET /test/\_search?q=\*&routing=rt1 returns only 2 docs - supposed to be 3  
> docs
> - GET /test/\_search?q=\*&routing=rt2 returns only 3 docs - supposed to be 4  
> docs
> - GET /test/\_search?q=\*&routing=rt3 returns 3 docs - supposed to be 1 doc
> 
> Please let me know what I'm doing wrong.  
> Thanks for your help.
> 
> Here's detail:  
> curl -XDELETE '[http://localhost:9200/test](http://localhost:9200/test)'  
> curl -XPUT '[http://localhost:9200/test](http://localhost:9200/test)' -d
> 
> '{"settings":{"number\_of\_shards":5,"number\_of\_replicas":0},"mappings":{"_default_":{"\_routing":{"path":"rt"}}}}'
> 
> curl -XPUT '[http://localhost:9200/test/type1/1](http://localhost:9200/test/type1/1)' -d  
> '{"file":"type1-1.txt","rt":"rt1"}'  
> curl -XPUT '[http://localhost:9200/test/type1/2](http://localhost:9200/test/type1/2)' -d  
> '{"file":"type1-2.txt","rt":"rt1"}'  
> curl -XPUT '[http://localhost:9200/test/type1/3](http://localhost:9200/test/type1/3)' -d  
> '{"file":"type1-3.txt","rt":"rt1"}'  
> curl -XPUT '[http://localhost:9200/test/type2/1](http://localhost:9200/test/type2/1)' -d  
> '{"file":"type2-1.txt","rt":"rt2"}'  
> curl -XPUT '[http://localhost:9200/test/type2/2](http://localhost:9200/test/type2/2)' -d  
> '{"file":"type2-2.txt","rt":"rt2"}'  
> curl -XPUT '[http://localhost:9200/test/type2/3](http://localhost:9200/test/type2/3)' -d  
> '{"file":"type2-3.txt","rt":"rt2"}'  
> curl -XPUT '[http://localhost:9200/test/type2/4](http://localhost:9200/test/type2/4)' -d  
> '{"file":"type2-4.txt","rt":"rt2"}'  
> curl -XPUT '[http://localhost:9200/test/type3/1](http://localhost:9200/test/type3/1)' -d  
> '{"file":"type3-1.txt","rt":"rt3"}'
> 
> - GET /test/\_status returns all 8 docs, but shard0 has 2 docs, shard1 has 3  
> docs, shard2 has 3 docs.
> - the distribution does not match the intention.
> 
> curl -XGET '[http://localhost:9200/test/\_status?pretty=true](http://localhost:9200/test/_status?pretty=true)'  
> {  
> "ok" : true,  
> "\_shards" : {  
> "total" : 5,   
> "indices" : {   
> "shards" : {  
> "0" : [ {   
> "docs" : {  
> "num\_docs" : 2,   
> "1" : [ {   
> "docs" : {  
> "num\_docs" : 3,   
> "2" : [ {   
> "docs" : {  
> "num\_docs" : 3,   
> "3" : [ {   
> "docs" : {  
> "num\_docs" : 0,   
> "4" : [ {   
> "docs" : {  
> "num\_docs" : 0,
> 
> - GET /test/\_search?q=\* returns all 8 docs
> 
> curl '[http://localhost:9200/test/\_search?q=\*&size=10&pretty=true](http://localhost:9200/test/_search?q=*&size=10&pretty=true)'  
> {  
> "took" : 84,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 8,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "test",  
> "\_type" : "type1",  
> "\_id" : "2",  
> "\_score" : 1.0, "\_source" : {"file":"type1-2.txt","rt":"rt1"}  
> }, {  
> "\_index" : "test",  
> "\_type" : "type1",  
> "\_id" : "3",  
> "\_score" : 1.0, "\_source" : {"file":"type1-3.txt","rt":"rt1"}  
> }, {  
> "\_index" : "test",  
> "\_type" : "type2",  
> "\_id" : "2",  
> "\_score" : 1.0, "\_source" : {"file":"type2-2.txt","rt":"rt2"}  
> }, {  
> "\_index" : "test",  
> "\_type" : "type2",  
> "\_id" : "3",  
> "\_score" : 1.0, "\_source" : {"file":"type2-3.txt","rt":"rt2"}  
> }, {  
> "\_index" : "test",  
> "\_type" : "type2",  
> "\_id" : "4",  
> "\_score" : 1.0, "\_source" : {"file":"type2-4.txt","rt":"rt2"}  
> }, {  
> "\_index" : "test",  
> "\_type" : "type1",  
> "\_id" : "1",  
> "\_score" : 1.0, "\_source" : {"file":"type1-1.txt","rt":"rt1"}  
> }, {  
> "\_index" : "test",  
> "\_type" : "type2",  
> "\_id" : "1",  
> "\_score" : 1.0, "\_source" : {"file":"type2-1.txt","rt":"rt2"}  
> }, {  
> "\_index" : "test",  
> "\_type" : "type3",  
> "\_id" : "1",  
> "\_score" : 1.0, "\_source" : {"file":"type3-1.txt","rt":"rt3"}  
> } ]  
> }  
> }
> 
> - GET /test/\_search?q=\*&routing=rt1 returns only 2 docs - supposed to be 3  
> docs
> 
> curl  
> '[http://localhost:9200/test/\_search?q=\*&size=10&pretty=true&routing=rt1](http://localhost:9200/test/_search?q=*&size=10&pretty=true&routing=rt1)'  
> {  
> "took" : 1,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 2,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "test",  
> "\_type" : "type1",  
> "\_id" : "2",  
> "\_score" : 1.0, "\_source" : {"file":"type1-2.txt","rt":"rt1"}  
> }, {  
> "\_index" : "test",  
> "\_type" : "type1",  
> "\_id" : "3",  
> "\_score" : 1.0, "\_source" : {"file":"type1-3.txt","rt":"rt1"}  
> } ]  
> }  
> }
> 
> - GET /test/\_search?q=\*&routing=rt2 returns only 3 docs - supposed to be 4  
> docs
> 
> curl  
> '[http://localhost:9200/test/\_search?q=\*&size=10&pretty=true&routing=rt2](http://localhost:9200/test/_search?q=*&size=10&pretty=true&routing=rt2)'  
> {  
> "took" : 2,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 3,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "test",  
> "\_type" : "type2",  
> "\_id" : "2",  
> "\_score" : 1.0, "\_source" : {"file":"type2-2.txt","rt":"rt2"}  
> }, {  
> "\_index" : "test",  
> "\_type" : "type2",  
> "\_id" : "3",  
> "\_score" : 1.0, "\_source" : {"file":"type2-3.txt","rt":"rt2"}  
> }, {  
> "\_index" : "test",  
> "\_type" : "type2",  
> "\_id" : "4",  
> "\_score" : 1.0, "\_source" : {"file":"type2-4.txt","rt":"rt2"}  
> } ]  
> }  
> }
> 
> - GET /test/\_search?q=\*&routing=rt3 returns 3 docs - supposed to be 1 doc
> 
> curl  
> '[http://localhost:9200/test/\_search?q=\*&size=10&pretty=true&routing=rt3](http://localhost:9200/test/_search?q=*&size=10&pretty=true&routing=rt3)'  
> {  
> "took" : 2,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 1,  
> "successful" : 1,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 3,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "test",  
> "\_type" : "type1",  
> "\_id" : "1",  
> "\_score" : 1.0, "\_source" : {"file":"type1-1.txt","rt":"rt1"}  
> }, {  
> "\_index" : "test",  
> "\_type" : "type2",  
> "\_id" : "1",  
> "\_score" : 1.0, "\_source" : {"file":"type2-1.txt","rt":"rt2"}  
> }, {  
> "\_index" : "test",  
> "\_type" : "type3",  
> "\_id" : "1",  
> "\_score" : 1.0, "\_source" : {"file":"type3-1.txt","rt":"rt3"}  
> } ]  
> }  
> }
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Routing-does-not-work-for-me-tp4001330.html](http://elasticsearch-users.115913.n3.nabble.com/Routing-does-not-work-for-me-tp4001330.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![arta](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@arta](https://discuss.elastic.co/u/arta)\
**Post date:** [May 22, 2012, 8:33pm UTC](https://discuss.elastic.co/t/routing-does-not-work-for-me/7766/3 "2012-05-22T20:33:55Z")

</div>

Thank you Kimchy, for the answer and suggestion.

---

<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:27am UTC](https://discuss.elastic.co/t/routing-does-not-work-for-me/7766/4 "2017-07-06T03:27:36Z")

</div>


