Skip to content

[DOCS] Reformat match phrase query #45204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/reference/analysis.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ to the inverted index:
------

[float]
[[specify-index-time-analyzer]]

=== Specifying an index time analyzer

Each <<text,`text`>> field in a mapping can specify its own
Expand Down
74 changes: 52 additions & 22 deletions docs/reference/query-dsl/match-phrase-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,21 @@
++++
<titleabbrev>Match phrase</titleabbrev>
++++
Returns documents that contain all words of a provided text, in the **same
order** as provided.

The `match_phrase` query analyzes the text and creates a `phrase` query
out of the analyzed text. For example:
You can use the `match_phrase` query when it's important to find a complete
phrase or words near each other.

[source,js]
--------------------------------------------------
GET /_search
{
"query": {
"match_phrase" : {
"message" : "this is a test"
}
}
}
--------------------------------------------------
// CONSOLE

A phrase query matches terms up to a configurable `slop`
(which defaults to 0) in any order. Transposed terms have a slop of 2.
[[match-phrase-query-ex-request]]
==== Example request

The following `match_phrase` search returns documents containing `brown fox` in
the `message` field.

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:
This search would match a `message` value of `quick brown fox` but not `the fox
is brown`.

[source,js]
--------------------------------------------------
Expand All @@ -34,13 +26,51 @@ GET /_search
"query": {
"match_phrase" : {
"message" : {
"query" : "this is a test",
"analyzer" : "my_analyzer"
"query" : "brown fox"
}
}
}
}
--------------------------------------------------
// CONSOLE

This query also accepts `zero_terms_query`, as explained in <<query-dsl-match-query, `match` query>>.

[[match-phrase-top-level-params]]
==== Top-level parameters for `match_phrase`
`<field>`::
(Required, object) Field you wish to search.

[[match-phrase-field-params]]
==== Parameters for `<field>`
`query`::
+
--
(Required, string) Text you wish to find in the provided `<field>`.

The `match_phrase` query <<analysis,analyzes>> any provided text into tokens
before performing a search.
--

`analyzer`::
(Optional, string) <<analysis,Analyzer>> used to convert text in the `query`
value into tokens. Defaults to the <<specify-index-time-analyzer,index-time
analyzer>> mapped for the `<field>`. If no analyzer is mapped, the index's
default analyzer is used.

`slop`::
(Optional, integer) Maximum number of positions allowed between matching tokens.
Defaults to `0`. Transposed terms have a slop of `2`.

`zero_terms_query`::
+
--
(Optional, string) Indicates whether no documents are returned if the `analyzer`
removes all tokens, such as when using a `stop` filter. Valid values are:

`none` (Default)::
No documents are returned if the `analyzer` removes all tokens.

`all`::
Returns all documents, similar to a <<query-dsl-match-all-query,`match_all`>>
query.
--