routing
The main problem is the document which should be stored in the slice
The actual process is calculated according to the formula partitioned
1 # routing hash value of the master slice number% 2 Shard = the hash (routing)% number_of_primary_shards . 3 # routing default value document _id
Custom routing
. 1 ? R1 the PUT / DOC / routing. 1 = user1 2 { . 3 " title " : " On the sow prenatal care " . 4 } . 5 ? The PUT R1 / DOC / 2 routing = user1 . 6 { . 7 " title " : " on the mother pig post-natal care " 8 }
Both of these documents are allocated on a slice of
By routing query document
GET r1/doc/1?routing=user1 # 结果如下 { "_index" : "r1", "_type" : "doc", "_id" : "1", "_version" : 3, "_routing" : "user1", "found" : true, "_source" : { "title" : " On the sow prenatal care " } }
Find the route by value
1 GET r1/doc/_search 2 { 3 "query": { 4 "terms": { 5 "_routing":["user1"] 6 } 7 } 8 } 9 # 结果如下 10 { 11 "took" : 0, 12 "timed_out" : false, 13 "_shards" : { 14 "total" : 5, 15 "successful" : 5, 16 "skipped" : 0, 17 "failed" : 0 18 }, 19 "hits" : { 20 "total" : 2, 21 "max_score" : 1.0, 22 "hits" : [ 23 { 24 "_index" : "r1", 25 "_type" : "doc", 26 "_id" : "2", 27 "_score" : 1.0, 28 "_routing" : "user1", 29 "_source" : { 30 "title" : "论母猪的产后护理" 31 } 32 }, 33 { 34 "_index" : "r1", 35 "_type" : "doc", 36 "_id" : "1", 37 "_score" : 1.0, 38 "_routing" : "user1", 39 "_source" : { 40 "title" : " } 41"On sows prenatal care 42 } 43 ] 44 } 45 }
Deleting a document routing will take or will not find value
DELETE r1/doc/1 # 结果如下 { "_index" : "r1", "_type" : "doc", "_id" : "1", "_version" : 1, "result" : "not_found", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 2, "_primary_term" : 1 } DELETE r1/doc/1?routing=user1 # 结果如下 { "_index" : "r1", "_type" : "doc", "_id" : "1", "_version" : 2, "result" : "deleted", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 4, "_primary_term" : 1 }
Query multiple routes
? PUT r2 / DOC / 1 routing = user1 { " title " : " Sow prenatal care with emphasis on multi-feed forage, supplemented by manual massage " } PUT r2 / DOC / 2 routing =? User2 { " title " : " Mother pigs post-natal care focusing on mother and child feeding isolation " }
Seek
GET r2/doc/_search?routing=user1,user2 { "query": { "match": { "title": "母猪" } } } # 结果如下 { "took" : 0, "timed_out" : false, "_shards" : { "total" : 2, "successful" : 2, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 2, "max_score" : 0.68324494, "hits" : [ { "_index" : "r2", "_type" : "doc", "_id" : "2", "_score" : .68324494 , " _routing " : " user2 " , " _Source " : { " title " : " sow post-natal care focusing on mother and child feeding isolation " } }, { " _index " : " r2 " , " _type " : " DOC " , " _id " : "1", "_score " : 0.5753642 , " _routing " : " user1 " , " _Source " : { " title " : " Sow prenatal care with emphasis on multi-feed forage, supplemented by manual massage " } } ] } }
Forget process routing (cause the document to be indexed in multiple parts)
? R3 the PUT / DOC / routing. 1 = U1 { " title " : " piglets very cute " } the PUT R3 / DOC / 2 { " title " : " and then a dish is cute " }
Inquire
GET r3/doc/_search { "query": { "terms": { "_routing":["u1"] } } } # 结果如下 { "took" : 1, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 1.0, "hits" : [ { "_index" : "r3", "_type" : "doc", "_id" : "1", "_score": 1.0 , " _routing " : " U1 " , " _Source " : { " title " : " piglets very cute " } } ] } }
Document 2 according to the general query, so two documents must be returned to avoid a situation like this
# The following is the written version 6.5.4 PUT r4 { " Mappings " : { " DOC " : { " _routing " : { " required " : to true } } } } # The following is the wording of official documents after 7.0 PUT my_index2 { " Mappings " : { " _ usting " : { " required " : to true } } }
During the operation of the document when it is necessary to bring the routing parameters
R4 PUT / DOC / 1 ? Routing parameters { " title " : " Sows not pregnant how to do? " }