mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-06 04:58:50 +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
86 lines
2.8 KiB
Plaintext
86 lines
2.8 KiB
Plaintext
[[query-dsl-match-bool-prefix-query]]
|
|
=== Match Bool Prefix Query
|
|
|
|
A `match_bool_prefix` query analyzes its input and constructs a
|
|
<<query-dsl-bool-query,`bool` query>> from the terms. Each term except the last
|
|
is used in a `term` query. The last term is used in a `prefix` query. A
|
|
`match_bool_prefix` query such as
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
GET /_search
|
|
{
|
|
"query": {
|
|
"match_bool_prefix" : {
|
|
"message" : "quick brown f"
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
|
|
where analysis produces the terms `quick`, `brown`, and `f` is similar to the
|
|
following `bool` query
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
GET /_search
|
|
{
|
|
"query": {
|
|
"bool" : {
|
|
"should": [
|
|
{ "term": { "message": "quick" }},
|
|
{ "term": { "message": "brown" }},
|
|
{ "prefix": { "message": "f"}}
|
|
]
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
|
|
An important difference between the `match_bool_prefix` query and
|
|
<<query-dsl-match-query-phrase-prefix,`match_phrase_prefix`>> is that the
|
|
`match_phrase_prefix` query matches its terms as a phrase, but the
|
|
`match_bool_prefix` query can match its terms in any position. The example
|
|
`match_bool_prefix` query above could match a field containing containing
|
|
`quick brown fox`, but it could also match `brown fox quick`. It could also
|
|
match a field containing the term `quick`, the term `brown` and a term
|
|
starting with `f`, appearing in any position.
|
|
|
|
==== Parameters
|
|
|
|
By default, `match_bool_prefix` queries' input text will be analyzed using the
|
|
analyzer from the queried field's mapping. A different search analyzer can be
|
|
configured with the `analyzer` parameter
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
GET /_search
|
|
{
|
|
"query": {
|
|
"match_bool_prefix" : {
|
|
"message": {
|
|
"query": "quick brown f",
|
|
"analyzer": "keyword"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
|
|
`match_bool_prefix` queries support the
|
|
<<query-dsl-minimum-should-match,`minimum_should_match`>> and `operator`
|
|
parameters as described for the
|
|
<<query-dsl-match-query-boolean,`match` query>>, applying the setting to the
|
|
constructed `bool` query. The number of clauses in the constructed `bool`
|
|
query will in most cases be the number of terms produced by analysis of the
|
|
query text.
|
|
|
|
The <<query-dsl-match-query-fuzziness,`fuzziness`>>, `prefix_length`,
|
|
`max_expansions`, `fuzzy_transpositions`, and `fuzzy_rewrite` parameters can
|
|
be applied to the `term` subqueries constructed for all terms but the final
|
|
term. They do not have any effect on the prefix query constructed for the
|
|
final term.
|