OpenSearch/docs/reference/query-dsl/prefix-query.asciidoc
Marios Trivyzas dac720d7a1
Add a cluster setting to disallow expensive queries (#51385) (#52279)
Add a new cluster setting `search.allow_expensive_queries` which by
default is `true`. If set to `false`, certain queries that have
usually slow performance cannot be executed and an error message
is returned.

- Queries that need to do linear scans to identify matches:
  - Script queries
- Queries that have a high up-front cost:
  - Fuzzy queries
  - Regexp queries
  - Prefix queries (without index_prefixes enabled
  - Wildcard queries
  - Range queries on text and keyword fields
- Joining queries
  - HasParent queries
  - HasChild queries
  - ParentId queries
  - Nested queries
- Queries on deprecated 6.x geo shapes (using PrefixTree implementation)
- Queries that may have a high per-document cost:
  - Script score queries
  - Percolate queries

Closes: #29050
(cherry picked from commit a8b39ed842c7770bd9275958c9f747502fd9a3ea)
2020-02-12 22:56:14 +01:00

74 lines
1.9 KiB
Plaintext

[[query-dsl-prefix-query]]
=== Prefix query
++++
<titleabbrev>Prefix</titleabbrev>
++++
Returns documents that contain a specific prefix in a provided field.
[[prefix-query-ex-request]]
==== Example request
The following search returns documents where the `user` field contains a term
that begins with `ki`.
[source,console]
----
GET /_search
{
"query": {
"prefix": {
"user": {
"value": "ki"
}
}
}
}
----
[[prefix-query-top-level-params]]
==== Top-level parameters for `prefix`
`<field>`::
(Required, object) Field you wish to search.
[[prefix-query-field-params]]
==== Parameters for `<field>`
`value`::
(Required, string) Beginning characters of terms you wish to find in the
provided `<field>`.
`rewrite`::
(Optional, string) Method used to rewrite the query. For valid values and more
information, see the <<query-dsl-multi-term-rewrite, `rewrite` parameter>>.
[[prefix-query-notes]]
==== Notes
[[prefix-query-short-ex]]
===== Short request example
You can simplify the `prefix` query syntax by combining the `<field>` and
`value` parameters. For example:
[source,console]
----
GET /_search
{
"query": {
"prefix" : { "user" : "ki" }
}
}
----
[[prefix-query-index-prefixes]]
===== Speed up prefix queries
You can speed up prefix queries using the <<index-prefixes,`index_prefixes`>>
mapping parameter. If enabled, {es} indexes prefixes between 2 and 5
characters in a separate field. This lets {es} run prefix queries more
efficiently at the cost of a larger index.
[[prefix-query-allow-expensive-queries]]
===== Allow expensive queries
Prefix queries will not be executed if <<query-dsl-allow-expensive-queries, `search.allow_expensive_queries`>>
is set to false. However, if <<index-prefixes, `index_prefixes`>> are enabled, an optimised query is built which
is not considered slow, and will be executed in spite of this setting.