2016-04-05 08:16:43 -04:00
|
|
|
[[query-dsl-match-query-phrase-prefix]]
|
|
|
|
=== Match Phrase Prefix Query
|
|
|
|
|
|
|
|
The `match_phrase_prefix` is the same as `match_phrase`, except that it
|
|
|
|
allows for prefix matches on the last term in the text. For example:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2016-05-24 05:58:43 -04:00
|
|
|
GET /_search
|
2016-04-05 08:16:43 -04:00
|
|
|
{
|
2016-05-24 05:58:43 -04:00
|
|
|
"query": {
|
|
|
|
"match_phrase_prefix" : {
|
|
|
|
"message" : "quick brown f"
|
|
|
|
}
|
2016-04-05 08:16:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-05-24 05:58:43 -04:00
|
|
|
// CONSOLE
|
2016-04-05 08:16:43 -04:00
|
|
|
|
|
|
|
It accepts the same parameters as the phrase type. In addition, it also
|
2016-04-22 06:45:12 -04:00
|
|
|
accepts a `max_expansions` parameter (default `50`) that can control to how
|
2017-05-30 09:01:13 -04:00
|
|
|
many suffixes the last term will be expanded. It is highly recommended to set
|
2016-04-22 06:45:12 -04:00
|
|
|
it to an acceptable value to control the execution time of the query. For
|
|
|
|
example:
|
2016-04-05 08:16:43 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2016-05-24 05:58:43 -04:00
|
|
|
GET /_search
|
2016-04-05 08:16:43 -04:00
|
|
|
{
|
2016-05-24 05:58:43 -04:00
|
|
|
"query": {
|
|
|
|
"match_phrase_prefix" : {
|
|
|
|
"message" : {
|
|
|
|
"query" : "quick brown f",
|
|
|
|
"max_expansions" : 10
|
|
|
|
}
|
2016-04-05 08:16:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-05-24 05:58:43 -04:00
|
|
|
// CONSOLE
|
2016-04-22 06:45:12 -04:00
|
|
|
|
|
|
|
[IMPORTANT]
|
|
|
|
===================================================
|
|
|
|
|
|
|
|
The `match_phrase_prefix` query is a poor-man's autocomplete. It is very easy
|
2017-05-30 09:01:13 -04:00
|
|
|
to use, which lets you get started quickly with _search-as-you-type_ but its
|
2016-04-22 06:45:12 -04:00
|
|
|
results, which usually are good enough, can sometimes be confusing.
|
|
|
|
|
|
|
|
Consider the query string `quick brown f`. This query works by creating a
|
|
|
|
phrase query out of `quick` and `brown` (i.e. the term `quick` must exist and
|
|
|
|
must be followed by the term `brown`). Then it looks at the sorted term
|
|
|
|
dictionary to find the first 50 terms that begin with `f`, and
|
|
|
|
adds these terms to the phrase query.
|
|
|
|
|
|
|
|
The problem is that the first 50 terms may not include the term `fox` so the
|
2017-05-30 09:01:13 -04:00
|
|
|
phrase `quick brown fox` will not be found. This usually isn't a problem as
|
2016-04-22 06:45:12 -04:00
|
|
|
the user will continue to type more letters until the word they are looking
|
|
|
|
for appears.
|
|
|
|
|
|
|
|
For better solutions for _search-as-you-type_ see the
|
|
|
|
<<search-suggesters-completion,completion suggester>> and
|
2016-09-01 20:41:44 -04:00
|
|
|
{defguide}/_index_time_search_as_you_type.html[Index-Time Search-as-You-Type].
|
2016-04-22 06:45:12 -04:00
|
|
|
|
2016-05-24 05:58:43 -04:00
|
|
|
===================================================
|