Let's forget about the shard placement and how to configure it--at least for a moment. In addition to all the fancy stuff that Elasticsearch allows us to set for shards and replicas, we also have the possibility to specify where our queries (and other operations, for example, the real-time GET) should be executed.
In order to control where the query (and other operations) we are sending will be executed, we can use the
preference parameter, which can be set to one of the following values:
_primary: Using this property, the operations we are sending will only be executed on primary shards. So, if we send a query against the
masteringindex with the preference parameter set to the
_primaryvalue, we would have it executed on the nodes with the names
node2. For example, if you know that your primary shards are in one rack and the replicas are in other racks, you may want to execute the operation on primary shards to avoid...