| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 | [[query-dsl-match-query-phrase-prefix]]=== Match phrase prefix query++++<titleabbrev>Match phrase prefix</titleabbrev>++++Returns documents that contain the words of a provided text, in the **sameorder** as provided. The last term of the provided text is treated as a<<query-dsl-prefix-query,prefix>>, matching any words that begin with that term.[[match-phrase-prefix-query-ex-request]]==== Example requestThe following search returns documents that contain phrases beginning with`quick brown f` in the `message` field.This search would match a `message` value of `quick brown fox` or `two quickbrown ferrets` but not `the fox is quick and brown`.[source,console]--------------------------------------------------GET /_search{    "query": {        "match_phrase_prefix" : {            "message" : {                "query" : "quick brown f"            }        }    }}--------------------------------------------------[[match-phrase-prefix-top-level-params]]==== Top-level parameters for `match_phrase_prefix``<field>`::(Required, object) Field you wish to search.[[match-phrase-prefix-field-params]]==== Parameters for `<field>``query`::+--(Required, string) Text you wish to find in the provided `<field>`. The `match_phrase_prefix` query <<analysis,analyzes>> any provided text intotokens before performing a search. The last term of this text is treated as a<<query-dsl-prefix-query,prefix>>, matching any words that begin with that term.--`analyzer`::(Optional, string) <<analysis,Analyzer>> used to convert text in the `query`value into tokens. Defaults to the <<specify-index-time-analyzer,index-timeanalyzer>> mapped for the `<field>`. If no analyzer is mapped, the index'sdefault analyzer is used.`max_expansions`::(Optional, integer) Maximum number of terms to which the last provided term ofthe `query` value will expand. Defaults to `50`.`slop`::(Optional, integer) Maximum number of positions allowed between matching tokens.Defaults to `0`. Transposed terms have a slop of `2`.`zero_terms_query`::+--(Optional, string) Indicates whether no documents are returned if the `analyzer`removes all tokens, such as when using a `stop` filter. Valid values are: `none` (Default)::No documents are returned if the `analyzer` removes all tokens. `all`::Returns all documents, similar to a <<query-dsl-match-all-query,`match_all`>>query.--[[match-phrase-prefix-query-notes]]==== Notes[[match-phrase-prefix-autocomplete]]===== Using the match phrase prefix query for search autocompletionWhile easy to set up, using the `match_phrase_prefix` query for searchautocompletion can sometimes produce confusing results.For example, consider the query string `quick brown f`. This query works bycreating a phrase query out of `quick` and `brown` (i.e. the term `quick` mustexist and must be followed by the term `brown`). Then it looks at the sortedterm dictionary to find the first 50 terms that begin with `f`, and adds theseterms to the phrase query.The problem is that the first 50 terms may not include the term `fox` so thephrase `quick brown fox` will not be found. This usually isn't a problem asthe user will continue to type more letters until the word they are lookingfor appears.For better solutions for _search-as-you-type_ see the<<completion-suggester,completion suggester>> andthe <<search-as-you-type,`search_as_you_type` field type>>.
 |