[DOCS] Rewrite 'wildcard' query (#42670)

This commit is contained in:
James Rodewig 2019-05-30 08:30:30 -04:00
parent 1beed9e71f
commit 67326252d8
1 changed files with 51 additions and 35 deletions

View File

@ -1,51 +1,67 @@
[[query-dsl-wildcard-query]] [[query-dsl-wildcard-query]]
=== Wildcard Query === Wildcard Query
Returns documents that contain terms matching a wildcard pattern.
Matches documents that have fields matching a wildcard expression (*not A wildcard operator is a placeholder that matches one or more characters. For
analyzed*). Supported wildcards are `*`, which matches any character example, the `*` wildcard operator matches zero or more characters. You can
sequence (including the empty one), and `?`, which matches any single combine wildcard operators with other characters to create a wildcard pattern.
character. Note that this query can be slow, as it needs to iterate over many
terms. In order to prevent extremely slow wildcard queries, a wildcard [[wildcard-query-ex-request]]
term should not start with one of the wildcards `*` or `?`. The wildcard ==== Example request
query maps to Lucene `WildcardQuery`.
The following search returns documents where the `user` field contains a term
that begins with `ki` and ends with `y`. These matching terms can include `kiy`,
`kity`, or `kimchy`.
[source,js] [source,js]
-------------------------------------------------- ----
GET /_search GET /_search
{ {
"query": { "query": {
"wildcard" : { "user" : "ki*y" } "wildcard": {
"user": {
"value": "ki*y",
"boost": 1.0,
"rewrite": "constant_score"
}
}
} }
} }
-------------------------------------------------- ----
// CONSOLE // CONSOLE
A boost can also be associated with the query: [[wildcard-top-level-params]]
==== Top-level parameters for `wildcard`
`<field>`::
Field you wish to search.
[source,js] [[wildcard-query-field-params]]
-------------------------------------------------- ==== Parameters for `<field>`
GET /_search `value`::
{ Wildcard pattern for terms you wish to find in the provided `<field>`.
"query": { +
"wildcard" : { "user" : { "value" : "ki*y", "boost" : 2.0 } } --
} This parameter supports two wildcard operators:
}
--------------------------------------------------
// CONSOLE
Or : * `?`, which matches any single character
* `*`, which can match zero or more characters, including an empty one
[source,js] WARNING: Avoid beginning patterns with `*` or `?`. This can increase
-------------------------------------------------- the iterations needed to find matching terms and slow search performance.
GET /_search --
{
"query": {
"wildcard" : { "user" : { "wildcard" : "ki*y", "boost" : 2.0 } }
}
}
--------------------------------------------------
// CONSOLE
This multi term query allows to control how it gets rewritten using the `boost`::
<<query-dsl-multi-term-rewrite,rewrite>> Floating point number used to decrease or increase the
parameter. <<query-filter-context, relevance scores>> of a query. Default is `1.0`.
Optional.
+
You can use the `boost` parameter to adjust relevance scores for searches
containing two or more queries.
+
Boost values are relative to the default value of `1.0`. A boost value between
`0` and `1.0` decreases the relevance score. A value greater than `1.0`
increases the relevance score.
`rewrite` (Expert)::
Method used to rewrite the query. For valid values and more information, see the
<<query-dsl-multi-term-rewrite, `rewrite` parameter>>. Optional.