We discussed before that an index contains one or more shards. During indexing, the document ID is used to determine which shard the document belongs to, using a simple formula as follows:
hash(document_id) % no_of_shards
To retrieve a document using the document ID, the same formula is used to determine the shard the document belongs to, and the document is retrieved:
When executing a search query, the node that receives the request is known as the coordinating node. The coordinating node (Node2) sends the query to all the shards of the index, aggregates the results, and sends them back to the client.
By default, a query has to be executed on all the shards of the index. But if you have a way to group similar data together, routing can be used to send the requests to a single shard instead of all the shards in the index.
For example, you want to use Elasticsearch...