<commit_before>[[mapping-routing-field]]
=== `_routing`

The routing field allows to control the `_routing` aspect when indexing
data and explicit routing control is required.

[float]
==== store / index

The first thing the `_routing` mapping does is to store the routing
value provided (`store` set to `false`) and index it (`index` set to
`not_analyzed`). The reason why the routing is stored by default is so
reindexing data will be possible if the routing value is completely
external and not part of the docs.

[float]
==== required

Another aspect of the `_routing` mapping is the ability to define it as
required by setting `required` to `true`. This is very important to set
when using routing features, as it allows different APIs to make use of
it. For example, an index operation will be rejected if no routing value
has been provided (or derived from the doc). A delete operation will be
broadcasted to all shards if no routing value is provided and `_routing`
is required.

[float]
==== path

The routing value can be provided as an external value when indexing
(and still stored as part of the document, in much the same way
`_source` is stored). But, it can also be automatically extracted from
the index doc based on a `path`. For example, having the following
mapping:

[source,js]
--------------------------------------------------
{
    "comment" : {
        "_routing" : {
            "required" : true,
            "path" : "blog.post_id"
        }
    }
}
--------------------------------------------------

Will cause the following doc to be routed based on the `111222` value:

[source,js]
--------------------------------------------------
{
    "text" : "the comment text"
    "blog" : {
        "post_id" : "111222"
    }
}
--------------------------------------------------

Note, using `path` without explicit routing value provided required an
additional (though quite fast) parsing phase.

[float]
==== id uniqueness

When indexing documents specifying a custom `_routing`, the uniqueness
of the `_id` is not guaranteed throughout all the shards that the index
is composed of. In fact, documents with the same `_id` might end up in
different shards if indexed with different `_routing` values.
<commit_msg>Doc has store "false" not store "true"<commit_after>[[mapping-routing-field]]
=== `_routing`

The routing field allows to control the `_routing` aspect when indexing
data and explicit routing control is required.

[float]
==== store / index

The first thing the `_routing` mapping does is to store the routing
value provided (`store` set to `true`) and index it (`index` set to
`not_analyzed`). The reason why the routing is stored by default is so
reindexing data will be possible if the routing value is completely
external and not part of the docs.

[float]
==== required

Another aspect of the `_routing` mapping is the ability to define it as
required by setting `required` to `true`. This is very important to set
when using routing features, as it allows different APIs to make use of
it. For example, an index operation will be rejected if no routing value
has been provided (or derived from the doc). A delete operation will be
broadcasted to all shards if no routing value is provided and `_routing`
is required.

[float]
==== path

The routing value can be provided as an external value when indexing
(and still stored as part of the document, in much the same way
`_source` is stored). But, it can also be automatically extracted from
the index doc based on a `path`. For example, having the following
mapping:

[source,js]
--------------------------------------------------
{
    "comment" : {
        "_routing" : {
            "required" : true,
            "path" : "blog.post_id"
        }
    }
}
--------------------------------------------------

Will cause the following doc to be routed based on the `111222` value:

[source,js]
--------------------------------------------------
{
    "text" : "the comment text"
    "blog" : {
        "post_id" : "111222"
    }
}
--------------------------------------------------

Note, using `path` without explicit routing value provided required an
additional (though quite fast) parsing phase.

[float]
==== id uniqueness

When indexing documents specifying a custom `_routing`, the uniqueness
of the `_id` is not guaranteed throughout all the shards that the index
is composed of. In fact, documents with the same `_id` might end up in
different shards if indexed with different `_routing` values.

{'fraction_non_alphanumeric': 0.15733333333333333, 'fraction_numerical': 0.005333333333333333, 'mean_word_length': 2.5921787709497206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1687067', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1122, 'n_words': 604}