Skip to content

Commit 8f46af6

Browse files
committed
[DOCS] Reformat match phrase prefix query (#45209)
1 parent 12c4a89 commit 8f46af6

File tree

2 files changed

+72
-33
lines changed

2 files changed

+72
-33
lines changed

docs/reference/analysis.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ to the inverted index:
3232
------
3333

3434
[float]
35+
[[specify-index-time-analyzer]]
3536
=== Specifying an index time analyzer
3637

3738
Each <<text,`text`>> field in a mapping can specify its own

docs/reference/query-dsl/match-phrase-prefix-query.asciidoc

Lines changed: 71 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,19 @@
44
<titleabbrev>Match phrase prefix</titleabbrev>
55
++++
66

7-
The `match_phrase_prefix` is the same as `match_phrase`, except that it
8-
allows for prefix matches on the last term in the text. For example:
7+
Returns documents that contain the words of a provided text, in the **same
8+
order** as provided. The last term of the provided text is treated as a
9+
<<query-dsl-prefix-query,prefix>>, matching any words that begin with that term.
910

10-
[source,js]
11-
--------------------------------------------------
12-
GET /_search
13-
{
14-
"query": {
15-
"match_phrase_prefix" : {
16-
"message" : "quick brown f"
17-
}
18-
}
19-
}
20-
--------------------------------------------------
21-
// CONSOLE
2211

23-
It accepts the same parameters as the phrase type. In addition, it also
24-
accepts a `max_expansions` parameter (default `50`) that can control to how
25-
many suffixes the last term will be expanded. It is highly recommended to set
26-
it to an acceptable value to control the execution time of the query. For
27-
example:
12+
[[match-phrase-prefix-query-ex-request]]
13+
==== Example request
14+
15+
The following search returns documents that contain phrases beginning with
16+
`quick brown f` in the `message` field.
17+
18+
This search would match a `message` value of `quick brown fox` or `two quick
19+
brown ferrets` but not `the fox is quick and brown`.
2820

2921
[source,js]
3022
--------------------------------------------------
@@ -33,35 +25,81 @@ GET /_search
3325
"query": {
3426
"match_phrase_prefix" : {
3527
"message" : {
36-
"query" : "quick brown f",
37-
"max_expansions" : 10
28+
"query" : "quick brown f"
3829
}
3930
}
4031
}
4132
}
4233
--------------------------------------------------
4334
// CONSOLE
4435

45-
[IMPORTANT]
46-
===================================================
4736

48-
The `match_phrase_prefix` query is a poor-man's autocomplete. It is very easy
49-
to use, which lets you get started quickly with _search-as-you-type_ but its
50-
results, which usually are good enough, can sometimes be confusing.
37+
[[match-phrase-prefix-top-level-params]]
38+
==== Top-level parameters for `match_phrase_prefix`
39+
`<field>`::
40+
(Required, object) Field you wish to search.
41+
42+
[[match-phrase-prefix-field-params]]
43+
==== Parameters for `<field>`
44+
`query`::
45+
+
46+
--
47+
(Required, string) Text you wish to find in the provided `<field>`.
48+
49+
The `match_phrase_prefix` query <<analysis,analyzes>> any provided text into
50+
tokens before performing a search. The last term of this text is treated as a
51+
<<query-dsl-prefix-query,prefix>>, matching any words that begin with that term.
52+
--
53+
54+
`analyzer`::
55+
(Optional, string) <<analysis,Analyzer>> used to convert text in the `query`
56+
value into tokens. Defaults to the <<specify-index-time-analyzer,index-time
57+
analyzer>> mapped for the `<field>`. If no analyzer is mapped, the index's
58+
default analyzer is used.
59+
60+
`max_expansions`::
61+
(Optional, integer) Maximum number of terms to which the last provided term of
62+
the `query` value will expand. Defaults to `50`.
63+
64+
`slop`::
65+
(Optional, integer) Maximum number of positions allowed between matching tokens.
66+
Defaults to `0`. Transposed terms have a slop of `2`.
67+
68+
`zero_terms_query`::
69+
+
70+
--
71+
(Optional, string) Indicates whether no documents are returned if the `analyzer`
72+
removes all tokens, such as when using a `stop` filter. Valid values are:
73+
74+
`none` (Default)::
75+
No documents are returned if the `analyzer` removes all tokens.
76+
77+
`all`::
78+
Returns all documents, similar to a <<query-dsl-match-all-query,`match_all`>>
79+
query.
80+
--
81+
82+
83+
[[match-phrase-prefix-query-notes]]
84+
==== Notes
85+
86+
[[match-phrase-prefix-autocomplete]]
87+
===== Using the match phrase prefix query for search autocompletion
88+
While easy to set up, using the `match_phrase_prefix` query for search
89+
autocompletion can sometimes produce confusing results.
5190

52-
Consider the query string `quick brown f`. This query works by creating a
53-
phrase query out of `quick` and `brown` (i.e. the term `quick` must exist and
54-
must be followed by the term `brown`). Then it looks at the sorted term
55-
dictionary to find the first 50 terms that begin with `f`, and
56-
adds these terms to the phrase query.
91+
For example, consider the query string `quick brown f`. This query works by
92+
creating a phrase query out of `quick` and `brown` (i.e. the term `quick` must
93+
exist and must be followed by the term `brown`). Then it looks at the sorted
94+
term dictionary to find the first 50 terms that begin with `f`, and adds these
95+
terms to the phrase query.
5796

5897
The problem is that the first 50 terms may not include the term `fox` so the
59-
phrase `quick brown fox` will not be found. This usually isn't a problem as
98+
phrase `quick brown fox` will not be found. This usually isn't a problem as
6099
the user will continue to type more letters until the word they are looking
61100
for appears.
62101

63102
For better solutions for _search-as-you-type_ see the
64103
<<search-suggesters-completion,completion suggester>> and
65104
{defguide}/_index_time_search_as_you_type.html[Index-Time Search-as-You-Type].
66105

67-
===================================================

0 commit comments

Comments
 (0)