elasticsearch/docs/reference/query-dsl/prefix-query.asciidoc
Luca Cavanna fe327c6e1a
[DOCS] Clarify index_prefix in prefix query docs (#87450)
The current docs mention that Elasticsearch indexes prefixes between 2 and 5 characters in a separate field. 2 and 5 are default values, and the size of the prefixes indexed depend on the configuration settings.
2022-06-14 14:32:37 +02:00

78 lines
2.1 KiB
Text

[[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.id` field contains a term
that begins with `ki`.
[source,console]
----
GET /_search
{
"query": {
"prefix": {
"user.id": {
"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>>.
`case_insensitive` added:[7.10.0] ::
(Optional, Boolean) Allows ASCII case insensitive matching of the
value with the indexed field values when set to true. Default is false which means
the case sensitivity of matching depends on the underlying field's mapping.
[[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 in a separate field,
according to the configuration settings. 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.