2016-04-05 08:16:43 -04:00
|
|
|
[[query-dsl-match-query-phrase]]
|
2019-07-18 10:18:11 -04:00
|
|
|
=== Match phrase query
|
|
|
|
++++
|
|
|
|
<titleabbrev>Match phrase</titleabbrev>
|
|
|
|
++++
|
2016-04-05 08:16:43 -04:00
|
|
|
|
|
|
|
The `match_phrase` query analyzes the text and creates a `phrase` query
|
|
|
|
out of the analyzed text. For example:
|
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2016-04-05 08:16:43 -04:00
|
|
|
--------------------------------------------------
|
2016-05-24 05:58:43 -04:00
|
|
|
GET /_search
|
2016-04-05 08:16:43 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"query": {
|
|
|
|
"match_phrase": {
|
|
|
|
"message": "this is a test"
|
2016-04-05 08:16:43 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2016-04-05 08:16:43 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
A phrase query matches terms up to a configurable `slop`
|
|
|
|
(which defaults to 0) in any order. Transposed terms have a slop of 2.
|
|
|
|
|
|
|
|
The `analyzer` can be set to control which analyzer will perform the
|
|
|
|
analysis process on the text. It defaults to the field explicit mapping
|
|
|
|
definition, or the default search analyzer, for example:
|
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2016-04-05 08:16:43 -04:00
|
|
|
--------------------------------------------------
|
2016-05-24 05:58:43 -04:00
|
|
|
GET /_search
|
2016-04-05 08:16:43 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"query": {
|
|
|
|
"match_phrase": {
|
|
|
|
"message": {
|
|
|
|
"query": "this is a test",
|
|
|
|
"analyzer": "my_analyzer"
|
|
|
|
}
|
2016-04-05 08:16:43 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2016-04-05 08:16:43 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2018-04-19 14:25:27 -04:00
|
|
|
|
|
|
|
This query also accepts `zero_terms_query`, as explained in <<query-dsl-match-query, `match` query>>.
|