WARNING: Version 2.3 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
A document is routed to a particular shard in an index using the following formula:
shard_num = hash(_routing) % num_primary_shards
Custom routing patterns can be implemented by specifying a custom
value per document. For instance:
This document uses
The value of the
_routing field is accessible in queries, aggregations, scripts,
and when sorting:
Querying on the
Aggregating on the
Sorting on the
Custom routing can reduce the impact of searches. Instead of having to fan out a search request to all the shards in an index, the request can be sent to just the shard that matches the specific routing value (or values):
Forgetting the routing value can lead to a document being indexed on more than
one shard. As a safeguard, the
_routing field can be configured to make a
routing value required for all CRUD operations:
When indexing documents specifying a custom
_routing, the uniqueness of the
_id is not guaranteed across all of the shards in the index. In fact,
documents with the same
_id might end up on different shards if indexed with
It is up to the user to ensure that IDs are unique across the index.