2013-08-28 19:24:34 -04:00
|
|
|
[[search-request-preference]]
|
|
|
|
=== Preference
|
|
|
|
|
|
|
|
Controls a `preference` of which shard replicas to execute the search
|
|
|
|
request on. By default, the operation is randomized between the shard
|
|
|
|
replicas.
|
|
|
|
|
2014-07-09 05:12:43 -04:00
|
|
|
The `preference` is a query string parameter which can be set to:
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[horizontal]
|
|
|
|
`_primary`::
|
|
|
|
The operation will go and be executed only on the primary
|
|
|
|
shards.
|
|
|
|
|
|
|
|
`_primary_first`::
|
|
|
|
The operation will go and be executed on the primary
|
|
|
|
shard, and if not available (failover), will execute on other shards.
|
|
|
|
|
|
|
|
`_local`::
|
|
|
|
The operation will prefer to be executed on a local
|
|
|
|
allocated shard if possible.
|
|
|
|
|
|
|
|
`_only_node:xyz`::
|
|
|
|
Restricts the search to execute only on a node with
|
|
|
|
the provided node id (`xyz` in this case).
|
|
|
|
|
|
|
|
`_prefer_node:xyz`::
|
|
|
|
Prefers execution on the node with the provided
|
|
|
|
node id (`xyz` in this case) if applicable.
|
|
|
|
|
|
|
|
`_shards:2,3`::
|
|
|
|
Restricts the operation to the specified shards. (`2`
|
|
|
|
and `3` in this case). This preference can be combined with other
|
|
|
|
preferences but it has to appear first: `_shards:2,3;_primary`
|
|
|
|
|
|
|
|
Custom (string) value::
|
|
|
|
A custom value will be used to guarantee that
|
|
|
|
the same shards will be used for the same custom value. This can help
|
|
|
|
with "jumping values" when hitting different shards in different refresh
|
|
|
|
states. A sample value can be something like the web session id, or the
|
|
|
|
user name.
|
|
|
|
|
2014-07-09 05:12:43 -04:00
|
|
|
For instance, use the user's session ID to ensure consistent ordering of results
|
|
|
|
for the user:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
------------------------------------------------
|
|
|
|
curl localhost:9200/_search?preference=xyzabc123 -d '
|
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"match": {
|
|
|
|
"title": "elasticsearch"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'
|
|
|
|
------------------------------------------------
|
|
|
|
|
|
|
|
|