Routing does not work for me, please help

(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'
curl -XPUT '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' -d
'{"file":"type1-1.txt","rt":"rt1"}'
curl -XPUT 'http://localhost:9200/test/type1/2' -d
'{"file":"type1-2.txt","rt":"rt1"}'
curl -XPUT 'http://localhost:9200/test/type1/3' -d
'{"file":"type1-3.txt","rt":"rt1"}'
curl -XPUT 'http://localhost:9200/test/type2/1' -d
'{"file":"type2-1.txt","rt":"rt2"}'
curl -XPUT 'http://localhost:9200/test/type2/2' -d
'{"file":"type2-2.txt","rt":"rt2"}'
curl -XPUT 'http://localhost:9200/test/type2/3' -d
'{"file":"type2-3.txt","rt":"rt2"}'
curl -XPUT 'http://localhost:9200/test/type2/4' -d
'{"file":"type2-4.txt","rt":"rt2"}'
curl -XPUT 'http://localhost:9200/test/type3/1' -d
'{"file":"type3-1.txt","rt":"rt3"}'
curl -XGET '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'
this returns all 8 docs
$ curl
'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'
this returns only 3 docs - supposed to be 4 docs
$ curl
'http://localhost:9200/test/_search?q=
&size=10&pretty=true&routing=rt3'
this returns 3 docs - supposed to be 1 doc

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.

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 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'
curl -XPUT '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' -d
'{"file":"type1-1.txt","rt":"rt1"}'
curl -XPUT 'http://localhost:9200/test/type1/2' -d
'{"file":"type1-2.txt","rt":"rt1"}'
curl -XPUT 'http://localhost:9200/test/type1/3' -d
'{"file":"type1-3.txt","rt":"rt1"}'
curl -XPUT 'http://localhost:9200/test/type2/1' -d
'{"file":"type2-1.txt","rt":"rt2"}'
curl -XPUT 'http://localhost:9200/test/type2/2' -d
'{"file":"type2-2.txt","rt":"rt2"}'
curl -XPUT 'http://localhost:9200/test/type2/3' -d
'{"file":"type2-3.txt","rt":"rt2"}'
curl -XPUT 'http://localhost:9200/test/type2/4' -d
'{"file":"type2-4.txt","rt":"rt2"}'
curl -XPUT 'http://localhost:9200/test/type3/1' -d
'{"file":"type3-1.txt","rt":"rt3"}'
curl -XGET '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'
this returns all 8 docs
$ curl '
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'
this returns only 3 docs - supposed to be 4 docs
$ curl '
http://localhost:9200/test/_search?q=*&size=10&pretty=true&routing=rt3'
this returns 3 docs - supposed to be 1 doc