Skip to content

Commit 5365767

Browse files
committed
[DOCS] Reformat match query (#45152)
1 parent b2f249f commit 5365767

File tree

1 file changed

+162
-8
lines changed

1 file changed

+162
-8
lines changed

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

Lines changed: 162 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,191 @@
44
<titleabbrev>Match</titleabbrev>
55
++++
66

7+
Returns documents that match a provided text, number, date or boolean value. The
8+
provided text is analyzed before matching.
79

8-
`match` queries accept text/numerics/dates, analyzes
9-
them, and constructs a query. For example:
10+
The `match` query is the standard query for performing a full-text search,
11+
including options for fuzzy matching.
12+
13+
14+
[[match-query-ex-request]]
15+
==== Example request
1016

1117
[source,js]
1218
--------------------------------------------------
1319
GET /_search
1420
{
1521
"query": {
1622
"match" : {
17-
"message" : "this is a test"
23+
"message" : {
24+
"query" : "this is a test"
25+
}
1826
}
1927
}
2028
}
2129
--------------------------------------------------
2230
// CONSOLE
2331

24-
Note, `message` is the name of a field, you can substitute the name of
25-
any field instead.
32+
33+
[[match-top-level-params]]
34+
==== Top-level parameters for `match`
35+
36+
`<field>`::
37+
(Required, object) Field you wish to search.
38+
39+
40+
[[match-field-params]]
41+
==== Parameters for `<field>`
42+
`query`::
43+
+
44+
--
45+
(Required) Text, number, boolean value or date you wish to find in the provided
46+
`<field>`.
47+
48+
The `match` query <<analysis,analyzes>> any provided text before performing a
49+
search. This means the `match` query can search <<text,`text`>> fields for
50+
analyzed tokens rather than an exact term.
51+
--
52+
53+
`analyzer`::
54+
(Optional, string) <<analysis,Analyzer>> used to convert the text in the `query`
55+
value into tokens. Defaults to the <<specify-index-time-analyzer,index-time
56+
analyzer>> mapped for the `<field>`. If no analyzer is mapped, the index's
57+
default analyzer is used.
58+
59+
`auto_generate_synonyms_phrase_query`::
60+
+
61+
--
62+
(Optional, boolean) If `true`, <<query-dsl-match-query-phrase,match phrase>>
63+
queries are automatically created for multi-term synonyms. Defaults to `true`.
64+
65+
See <<query-dsl-match-query-synonyms,Use synonyms with match query>> for an
66+
example.
67+
--
68+
69+
`fuzziness`::
70+
(Optional, string) Maximum edit distance allowed for matching. See <<fuzziness>>
71+
for valid values and more information. See <<query-dsl-match-query-fuzziness>>
72+
for an example.
73+
74+
`max_expansions`::
75+
(Optional, integer) Maximum number of terms to which the query will
76+
expand. Defaults to `50`.
77+
78+
`prefix_length`::
79+
(Optional, integer) Number of beginning characters left unchanged for fuzzy
80+
matching. Defaults to `0`.
81+
82+
`transpositions`::
83+
(Optional, boolean) If `true`, edits for fuzzy matching include
84+
transpositions of two adjacent characters (ab → ba). Defaults to `true`.
85+
86+
`fuzzy_rewrite`::
87+
+
88+
--
89+
(Optional, string) Method used to rewrite the query. See the
90+
<<query-dsl-multi-term-rewrite, `rewrite` parameter>> for valid values and more
91+
information.
92+
93+
If the `fuzziness` parameter is not `0`, the `match` query uses a `rewrite`
94+
method of `top_terms_blended_freqs_${max_expansions}` by default.
95+
--
96+
97+
`lenient`::
98+
(Optional, boolean) If `true`, format-based errors, such as providing a text
99+
`query` value for a <<number,numeric>> field, are ignored. Defaults to `false`.
100+
101+
`operator`::
102+
+
103+
--
104+
(Optional, string) Boolean logic used to interpret text in the `query` value.
105+
Valid values are:
106+
107+
`OR` (Default)::
108+
For example, a `query` value of `capital of Hungary` is interpreted as `capital
109+
OR of OR Hungary`.
110+
111+
`AND`::
112+
For example, a `query` value of `capital of Hungary` is interpreted as `capital
113+
AND of AND Hungary`.
114+
--
115+
116+
`minimum_should_match`::
117+
+
118+
--
119+
(Optional, string) Minimum number of clauses that must match for a document to
120+
be returned. See the <<query-dsl-minimum-should-match, `minimum_should_match`
121+
parameter>> for valid values and more information.
122+
--
123+
124+
`zero_terms_query`::
125+
+
126+
--
127+
(Optional, string) Indicates whether no documents are returned if the `analyzer`
128+
removes all tokens, such as when using a `stop` filter. Valid values are:
129+
130+
`none` (Default)::
131+
No documents are returned if the `analyzer` removes all tokens.
132+
133+
`all`::
134+
Returns all documents, similar to a <<query-dsl-match-all-query,`match_all`>>
135+
query.
136+
137+
See <<query-dsl-match-query-zero>> for an example.
138+
--
139+
140+
141+
[[match-query-notes]]
142+
==== Notes
143+
144+
[[query-dsl-match-query-short-ex]]
145+
===== Short request example
146+
147+
You can simplify the match query syntax by combining the `<field>` and `query`
148+
parameters. For example:
149+
150+
[source,js]
151+
----
152+
GET /_search
153+
{
154+
"query": {
155+
"match" : {
156+
"message" : "this is a test"
157+
}
158+
}
159+
}
160+
----
161+
// CONSOLE
26162

27163
[[query-dsl-match-query-boolean]]
28-
==== match
164+
===== How the match query works
29165

30166
The `match` query is of type `boolean`. It means that the text
31167
provided is analyzed and the analysis process constructs a boolean query
32-
from the provided text. The `operator` flag can be set to `or` or `and`
168+
from the provided text. The `operator` parameter can be set to `or` or `and`
33169
to control the boolean clauses (defaults to `or`). The minimum number of
34170
optional `should` clauses to match can be set using the
35171
<<query-dsl-minimum-should-match,`minimum_should_match`>>
36172
parameter.
37173

174+
Here is an example with the `operator` parameter:
175+
176+
[source,js]
177+
--------------------------------------------------
178+
GET /_search
179+
{
180+
"query": {
181+
"match" : {
182+
"message" : {
183+
"query" : "this is a test",
184+
"operator" : "and"
185+
}
186+
}
187+
}
188+
}
189+
--------------------------------------------------
190+
// CONSOLE
191+
38192
The `analyzer` can be set to control which analyzer will perform the
39193
analysis process on the text. It defaults to the field explicit mapping
40194
definition, or the default search analyzer.
@@ -44,7 +198,7 @@ data-type mismatches, such as trying to query a numeric field with a text
44198
query string. Defaults to `false`.
45199

46200
[[query-dsl-match-query-fuzziness]]
47-
===== Fuzziness
201+
===== Fuzziness in the match query
48202

49203
`fuzziness` allows _fuzzy matching_ based on the type of field being queried.
50204
See <<fuzziness>> for allowed settings.

0 commit comments

Comments
 (0)