# Routing does not work for me, please help

**URL:** <https://discuss.elastic.co/t/routing-does-not-work-for-me-please-help/7730>\
**Category:** Elasticsearch\
**Created:** [May 16, 2012, 11:43pm UTC](https://discuss.elastic.co/t/routing-does-not-work-for-me-please-help/7730 "2012-05-16T23:43:11Z")\
**Posts on this page:** 3\
**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 16, 2012, 11:43pm UTC](https://discuss.elastic.co/t/routing-does-not-work-for-me-please-help/7730/1 "2012-05-16T23:43:11Z")

</div>

(My previous post for the same topic seems to be rejected maybe because it  
was too long. here's short version. apologies if this duplicates)  
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"}'  
curl -XGET '[http://localhost:9200/test/\_status?pretty=true](http://localhost:9200/test/_status?pretty=true)'  
this 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 '[http://localhost:9200/test/\_search?q=](http://localhost:9200/test/_search?q=)_&size=10&pretty=true'  
this returns all 8 docs  
$ curl  
'[http://localhost:9200/test/\_search?q=](http://localhost:9200/test/_search?q=)_&size=10&pretty=true&routing=rt1'  
this returns only 2 docs - supposed to be 3 docs  
$ curl  
'[http://localhost:9200/test/\_search?q=](http://localhost:9200/test/_search?q=)_&size=10&pretty=true&routing=rt2'  
this returns only 3 docs - supposed to be 4 docs  
$ curl  
'[http://localhost:9200/test/\_search?q=](http://localhost:9200/test/_search?q=)_&size=10&pretty=true&routing=rt3'  
this returns 3 docs - supposed to be 1 doc

---

<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, 6:19pm UTC](https://discuss.elastic.co/t/routing-does-not-work-for-me-please-help/7730/2 "2012-05-20T18:19:08Z")

</div>

Heya, this is a bug because of the _default_ mapping and introducing a type  
through indexing a document, opened an issue:  
[Mapping: Using \_default\_ mapping \_routing mapping definition fails to apply when introducing type through indexing · Issue #1967 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1967).

For now, you can overcome it by explicitly specifying the mappings in the  
index.

Btw, it is recommended when setting path is to also set required to true,  
in which case indexing will fail if no routing is detected. There is  
another bug related to _default_ (which is simpler to fix).

On Thu, May 17, 2012 at 1:43 AM, arta [artasano@sbcglobal.net](mailto:artasano@sbcglobal.net) wrote:

> (My previous post for the same topic seems to be rejected maybe because it  
> was too long. here's short version. apologies if this duplicates)  
> 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"}'  
> curl -XGET '[http://localhost:9200/test/\_status?pretty=true](http://localhost:9200/test/_status?pretty=true)'  
> this 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 '[http://localhost:9200/test/\_search?q=\*&size=10&pretty=true](http://localhost:9200/test/_search?q=*&size=10&pretty=true)'  
> this returns all 8 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)'  
> this returns only 2 docs - supposed to be 3 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)'  
> this returns only 3 docs - supposed to be 4 docs  
> $ 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)'  
> this returns 3 docs - supposed to be 1 doc

---

<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:28am UTC](https://discuss.elastic.co/t/routing-does-not-work-for-me-please-help/7730/3 "2017-07-06T03:28:03Z")

</div>


