(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'
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"}'
- 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'
{
"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'
{
"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'
{
"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'
{
"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'
{
"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"}
} ]
}
}