| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 | [[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 requestThe following search returns documents where the `user.id` field contains a termthat 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 theprovided `<field>`.`rewrite`::(Optional, string) Method used to rewrite the query. For valid values and moreinformation, see the <<query-dsl-multi-term-rewrite, `rewrite` parameter>>.[[prefix-query-notes]]==== Notes[[prefix-query-short-ex]]===== Short request exampleYou 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 queriesYou can speed up prefix queries using the <<index-prefixes,`index_prefixes`>>mapping parameter. If enabled, {es} indexes prefixes between 2 and 5characters in a separate field. This lets {es} run prefix queries moreefficiently at the cost of a larger index.[[prefix-query-allow-expensive-queries]]===== Allow expensive queriesPrefix 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 whichis not considered slow, and will be executed in spite of this setting.
 |