Span multi-term query
The span_multi query allows you to wrap a multi term query (one of wildcard, fuzzy, prefix, range or regexp query) as a span query, so it can be nested. Example:
resp = client.search(
query={
"span_multi": {
"match": {
"prefix": {
"user.id": {
"value": "ki"
}
}
}
}
},
)
print(resp) response = client.search(
body: {
query: {
span_multi: {
match: {
prefix: {
'user.id' => {
value: 'ki'
}
}
}
}
}
}
)
puts response const response = await client.search({
query: {
span_multi: {
match: {
prefix: {
"user.id": {
value: "ki",
},
},
},
},
},
});
console.log(response); GET /_search
{
"query": {
"span_multi": {
"match": {
"prefix": { "user.id": { "value": "ki" } }
}
}
}
} A boost can also be associated with the query:
resp = client.search(
query={
"span_multi": {
"match": {
"prefix": {
"user.id": {
"value": "ki",
"boost": 1.08
}
}
}
}
},
)
print(resp) response = client.search(
body: {
query: {
span_multi: {
match: {
prefix: {
'user.id' => {
value: 'ki',
boost: 1.08
}
}
}
}
}
}
)
puts response const response = await client.search({
query: {
span_multi: {
match: {
prefix: {
"user.id": {
value: "ki",
boost: 1.08,
},
},
},
},
},
});
console.log(response); GET /_search
{
"query": {
"span_multi": {
"match": {
"prefix": { "user.id": { "value": "ki", "boost": 1.08 } }
}
}
}
} span_multi queries will hit too many clauses failure if the number of terms that match the query exceeds the indices.query.bool.max_clause_count search setting. To avoid an unbounded expansion you can set the 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_prefixes field option of the text field instead. This will rewrite any prefix query on the field to a single term query that matches the indexed prefix.
© 2023-2025 Elasticsearch
As of September 2024, Elasticsearch is available under a choice of three licenses: the Server Side Public License (SSPL), the Elastic License, or the AGPLv3 (OSI approved).
Elasticsearch and the Elasticsearch logo are trademarks of Elasticsearch B.V., registered in the U.S. and in other countries.
https://www.elastic.co/guide/en/elasticsearch/reference/8.17/query-dsl-span-multi-term-query.html