OpenSearch/docs/reference/query-dsl/prefix-query.asciidoc

69 lines
1.5 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,js]
----
GET /_search
{
"query": {
"prefix": {
"user": {
"value": "ki"
}
}
}
}
----
// CONSOLE
[[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,js]
----
GET /_search
{
"query": {
"prefix" : { "user" : "ki" }
}
}
----
// CONSOLE
[[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.