IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Prefix query
edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.
Prefix query
editReturns documents that contain a specific prefix in a provided field.
Example request
editThe following search returns documents where the user field contains a term
that begins with ki.
GET /_search
{
"query": {
"prefix": {
"user": {
"value": "ki"
}
}
}
}
Top-level parameters for prefix
edit-
<field> - (Required, object) Field you wish to search.
Parameters for <field>
edit-
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
rewriteparameter.
Notes
editShort request example
editYou can simplify the prefix query syntax by combining the <field> and
value parameters. For example:
GET /_search
{
"query": {
"prefix" : { "user" : "ki" }
}
}
Speed up prefix queries
editYou can speed up prefix queries using the index_prefixes
mapping parameter. If enabled, Elasticsearch indexes prefixes between 2 and 5
characters in a separate field. This lets Elasticsearch run prefix queries more
efficiently at the cost of a larger index.