mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-11 07:25:23 +00:00
Adds the search_as_you_type field type that acts like a text field optimized for as-you-type search completion. It creates a couple subfields that analyze the indexed terms as shingles, against which full terms are queried, and a prefix subfield that analyze terms as the largest shingle size used and edge-ngrams, against which partial terms are queried Adds a match_bool_prefix query type that creates a boolean clause of a term query for each term except the last, for which a boolean clause with a prefix query is created. The match_bool_prefix query is the recommended way of querying a search as you type field, which will boil down to term queries for each shingle of the input text on the appropriate shingle field, and the final (possibly partial) term as a term query on the prefix field. This field type also supports phrase and phrase prefix queries however
65 lines
2.1 KiB
Plaintext
65 lines
2.1 KiB
Plaintext
[[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]
|
|
--------------------------------------------------
|
|
GET /_search
|
|
{
|
|
"query": {
|
|
"match_phrase_prefix" : {
|
|
"message" : "quick brown f"
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
|
|
It accepts the same parameters as the phrase type. In addition, it also
|
|
accepts a `max_expansions` parameter (default `50`) that can control to how
|
|
many suffixes the last term will be expanded. It is highly recommended to set
|
|
it to an acceptable value to control the execution time of the query. For
|
|
example:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
GET /_search
|
|
{
|
|
"query": {
|
|
"match_phrase_prefix" : {
|
|
"message" : {
|
|
"query" : "quick brown f",
|
|
"max_expansions" : 10
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
|
|
[IMPORTANT]
|
|
===================================================
|
|
|
|
The `match_phrase_prefix` query is a poor-man's autocomplete. It is very easy
|
|
to use, which lets you get started quickly with _search-as-you-type_ but its
|
|
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
|
|
phrase `quick brown fox` will not be found. This usually isn't a problem as
|
|
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
|
|
the <<search-as-you-type,`search_as_you_type` field type>>.
|
|
|
|
===================================================
|