routing-field.asciidoc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. [[mapping-routing-field]]
  2. === `_routing`
  3. The routing field allows to control the `_routing` aspect when indexing
  4. data and explicit routing control is required.
  5. [float]
  6. ==== store / index
  7. The first thing the `_routing` mapping does is to store the routing
  8. value provided (`store` set to `yes`) and index it (`index` set to
  9. `not_analyzed`). The reason why the routing is stored by default is so
  10. reindexing data will be possible if the routing value is completely
  11. external and not part of the docs.
  12. [float]
  13. ==== required
  14. Another aspect of the `_routing` mapping is the ability to define it as
  15. required by setting `required` to `true`. This is very important to set
  16. when using routing features, as it allows different APIs to make use of
  17. it. For example, an index operation will be rejected if no routing value
  18. has been provided (or derived from the doc). A delete operation will be
  19. broadcasted to all shards if no routing value is provided and `_routing`
  20. is required.
  21. [float]
  22. ==== path
  23. The routing value can be provided as an external value when indexing
  24. (and still stored as part of the document, in much the same way
  25. `_source` is stored). But, it can also be automatically extracted from
  26. the index doc based on a `path`. For example, having the following
  27. mapping:
  28. [source,js]
  29. --------------------------------------------------
  30. {
  31. "comment" : {
  32. "_routing" : {
  33. "required" : true,
  34. "path" : "blog.post_id"
  35. }
  36. }
  37. }
  38. --------------------------------------------------
  39. Will cause the following doc to be routed based on the `111222` value:
  40. [source,js]
  41. --------------------------------------------------
  42. {
  43. "text" : "the comment text"
  44. "blog" : {
  45. "post_id" : "111222"
  46. }
  47. }
  48. --------------------------------------------------
  49. Note, using `path` without explicit routing value provided required an
  50. additional (though quite fast) parsing phase.
  51. [float]
  52. ==== id uniqueness
  53. When indexing documents specifying a custom `_routing`, the uniqueness
  54. of the `_id` is not guaranteed throughout all the shards that the index
  55. is composed of. In fact, documents with the same `_id` might end up in
  56. different shards if indexed with different `_routing` values.