1
1
[[search-request-preference]]
2
2
=== Preference
3
3
4
- Controls a `preference` of which shard copies on which to execute the
5
- search. By default, the operation is randomized among the available shard
6
- copies, unless allocation awareness is used.
4
+ Controls a `preference` of which shard copies on which to execute the search.
5
+ By default, Elasticsearch selects from the available shard copies in an
6
+ unspecified order, taking the <<allocation-awareness,allocation awareness>> and
7
+ <<search-adaptive-replica,adaptive replica selection>> configuration into
8
+ account. However, it may sometimes be desirable to try and route certain
9
+ searches to certain sets of shard copies, for instance to make better use of
10
+ per-copy caches.
11
+
12
+ Preferences do not _guarantee_ that any particular shard copies are used in a
13
+ search, and on a changing index this may mean that repeated searches may yield
14
+ different results if they are executed on different shard copies which are in
15
+ different refresh states.
7
16
8
17
The `preference` is a query string parameter which can be set to:
9
18
10
19
[horizontal]
11
- `_primary`::
12
- The operation will go and be executed only on the primary
13
- shards. deprecated[6.1.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`]
20
+ `_primary`::
21
+ The operation will be executed only on primary shards.
22
+ deprecated[6.1.0, will be removed in 7.0, use `_only_nodes` or
23
+ `_prefer_nodes`]
14
24
15
- `_primary_first`::
16
- The operation will go and be executed on the primary
17
- shard, and if not available (failover) , will execute on other shards.
18
- deprecated[6.1.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`]
25
+ `_primary_first`::
26
+ The operation will be executed on primary shards if possible, but will
27
+ fall back to other shards if not. deprecated[6.1.0 , will be removed in
28
+ 7.0, use `_only_nodes` or `_prefer_nodes`]
19
29
20
30
`_replica`::
21
- The operation will go and be executed only on a replica shard.
22
- deprecated[6.1.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`]
31
+ The operation will be executed only on replica shards. If there are
32
+ multiple replicas then the order of preference between them is
33
+ unspecified. deprecated[6.1.0, will be removed in 7.0, use
34
+ `_only_nodes` or `_prefer_nodes`]
23
35
24
36
`_replica_first`::
25
- The operation will go and be executed only on a replica shard, and if
26
- not available (failover), will execute on other shards.
27
- deprecated[6.1.0, will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`]
37
+ The operation will be executed on replica shards if possible, but will
38
+ fall back to other shards if not. If there are multiple replicas then
39
+ the order of preference between them is unspecified. deprecated[6.1.0,
40
+ will be removed in 7.0, use `_only_nodes` or `_prefer_nodes`]
41
+
42
+ `_only_local`::
43
+ The operation will be executed only on shards allocated to the local
44
+ node.
28
45
29
- `_local`::
30
- The operation will prefer to be executed on a local
31
- allocated shard if possible .
46
+ `_local`::
47
+ The operation will be executed on shards allocated to the local node if
48
+ possible, and will fall back to other shards if not .
32
49
33
50
`_prefer_nodes:abc,xyz`::
34
- Prefers execution on the nodes with the provided
35
- node ids (`abc` or `xyz` in this case) if applicable.
51
+ The operation will be executed on nodes with one of the provided node
52
+ ids (`abc` or `xyz` in this case) if possible. If suitable shard copies
53
+ exist on more than one of the selected nodes then the order of
54
+ preference between these copies is unspecified.
36
55
37
- `_shards:2,3`::
38
- Restricts the operation to the specified shards. (`2`
39
- and `3` in this case). This preference can be combined with other
40
- preferences but it has to appear first: `_shards:2,3|_local`
56
+ `_shards:2,3`::
57
+ Restricts the operation to the specified shards. (`2` and `3` in this
58
+ case). This preference can be combined with other preferences but it
59
+ has to appear first: `_shards:2,3|_local`
41
60
42
- `_only_nodes`::
43
- Restricts the operation to nodes specified in <<cluster,node specification>>
61
+ `_only_nodes:abc*,x*yz,...`::
62
+ Restricts the operation to nodes specified according to the
63
+ <<cluster,node specification>>. If suitable shard copies exist on more
64
+ than one of the selected nodes then the order of preference between
65
+ these copies is unspecified.
44
66
45
- Custom (string) value::
46
- A custom value will be used to guarantee that
47
- the same shards will be used for the same custom value. This can help
48
- with "jumping values" when hitting different shards in different refresh
49
- states. A sample value can be something like the web session id, or the
50
- user name.
67
+ Custom (string) value::
68
+ Any value that does not start with `_`. If two searches both give the same
69
+ custom string value for their preference and the underlying cluster state
70
+ does not change then the same ordering of shards will be used for the
71
+ searches. This does not guarantee that the exact same shards will be used
72
+ each time: the cluster state, and therefore the selected shards, may change
73
+ for a number of reasons including shard relocations and shard failures, and
74
+ nodes may sometimes reject searches causing fallbacks to alternative nodes.
75
+ A good candidate for a custom preference value is something like the web
76
+ session id or the user name.
51
77
52
- For instance, use the user's session ID to ensure consistent ordering of results
53
- for the user:
78
+ For instance, use the user's session ID `xyzabc123` as follows:
54
79
55
80
[source,js]
56
81
------------------------------------------------
@@ -65,3 +90,12 @@ GET /_search?preference=xyzabc123
65
90
------------------------------------------------
66
91
// CONSOLE
67
92
93
+ WARNING: The `_primary`, `_primary_first`, `_replica` and `_replica_first` are
94
+ not recommended, and will be removed in a future version. They do not help to
95
+ avoid inconsistent results that arise from the use of shards that have
96
+ different refresh states, and Elasticsearch uses synchronous replication so the
97
+ primary does not in general hold fresher data than its replicas. The
98
+ `_primary_first` and `_replica_first` preferences silently fall back to
99
+ non-preferred copies if it is not possible to search the preferred copies. The
100
+ `_primary` and `_replica` preferences will silently change their preferred
101
+ shards if a replica is promoted to primary, which can happen at any time.
0 commit comments