2013-08-29 01:24:34 +02:00
|
|
|
[[query-dsl-span-multi-term-query]]
|
2015-06-04 01:59:22 +02:00
|
|
|
=== Span Multi Term Query
|
2013-08-29 01:24:34 +02:00
|
|
|
|
2015-02-05 21:23:52 +01:00
|
|
|
The `span_multi` query allows you to wrap a `multi term query` (one of wildcard,
|
2017-01-24 03:33:12 +11:00
|
|
|
fuzzy, prefix, range or regexp query) as a `span query`, so
|
2013-08-29 01:24:34 +02:00
|
|
|
it can be nested. Example:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2016-05-24 11:58:43 +02:00
|
|
|
GET /_search
|
2013-08-29 01:24:34 +02:00
|
|
|
{
|
2016-05-24 11:58:43 +02:00
|
|
|
"query": {
|
|
|
|
"span_multi":{
|
|
|
|
"match":{
|
|
|
|
"prefix" : { "user" : { "value" : "ki" } }
|
|
|
|
}
|
2013-08-29 01:24:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-05-24 11:58:43 +02:00
|
|
|
// CONSOLE
|
2013-08-29 01:24:34 +02:00
|
|
|
|
|
|
|
A boost can also be associated with the query:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2016-05-24 11:58:43 +02:00
|
|
|
GET /_search
|
2013-08-29 01:24:34 +02:00
|
|
|
{
|
2016-05-24 11:58:43 +02:00
|
|
|
"query": {
|
|
|
|
"span_multi":{
|
|
|
|
"match":{
|
|
|
|
"prefix" : { "user" : { "value" : "ki", "boost" : 1.08 } }
|
|
|
|
}
|
2013-08-29 01:24:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-05-24 11:58:43 +02:00
|
|
|
// CONSOLE
|
2018-06-04 21:48:56 +02:00
|
|
|
|
|
|
|
WARNING: By default `span_multi queries are rewritten to a `span_or` query
|
|
|
|
containing **all** the expanded terms. This can be expensive if the number of expanded
|
|
|
|
terms is large. To avoid an unbounded expansion you can set the
|
|
|
|
<<query-dsl-multi-term-rewrite,rewrite method>> of the multi term query to `top_terms_*`
|
|
|
|
rewrite. Or, if you use `span_multi` on `prefix` query only, you can
|
|
|
|
activate the <<index-prefix-config,`index_prefixes`>> field option of the `text` field instead. This will
|
|
|
|
rewrite any prefix query on the field to a a single term query that matches the indexed prefix.
|