Span multi-term 查询
span_multi
查询允许您将多词条查询(例如 wildcard
、fuzzy
、prefix
、range
或 regexp
)封装为跨度查询。这使您可以在其他跨度查询中使用这些更灵活的匹配查询。
例如,您可以使用 span_multi
查询来
- 查找与其他词条附近具有共同前缀的词。
- 在跨度内匹配词语的模糊变体。
- 在跨度查询中使用正则表达式。
span_multi
查询可能会匹配许多词条。为避免内存使用过多,您可以
- 为多词条查询设置
rewrite
参数。- 使用
top_terms_*
重写方法。- 如果您仅将
span_multi
用于prefix
查询,请考虑为文本字段启用index_prefixes
选项。这会自动将字段上的任何prefix
查询重写为匹配索引前缀的单词条查询。
示例
要尝试本节中的示例,请完成设置步骤。
span_multi
查询使用以下语法来封装 prefix
查询
"span_multi": {
"match": {
"prefix": {
"description": {
"value": "flutter"
}
}
}
}
以下查询搜索以“dress”开头且与任何形式的“sleeve”相距最多 5 个词的词
GET /clothing/_search
{
"query": {
"span_near": {
"clauses": [
{
"span_multi": {
"match": {
"prefix": {
"description": {
"value": "dress"
}
}
}
}
},
{
"field_masking_span": {
"query": {
"span_term": {
"description.stemmed": "sleev"
}
},
"field": "description"
}
}
],
"slop": 5,
"in_order": false
}
}
}
该查询匹配文档 1(“Long-sleeved dress…”)和文档 4(“…dresses with long fluttered sleeves…”),因为“dress”和“long”在两个文档中都出现在最大距离内。
响应
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 1.7590723,
"hits": [
{
"_index": "clothing",
"_id": "1",
"_score": 1.7590723,
"_source": {
"description": "Long-sleeved dress shirt with a formal collar and button cuffs. "
}
},
{
"_index": "clothing",
"_id": "4",
"_score": 0.84792376,
"_source": {
"description": "A set of two midi silk shirt dresses with long fluttered sleeves in black. "
}
}
]
}
}
参数
下表列出了 span_multi
查询支持的所有顶级参数。所有参数均为必填项。
参数 | 数据类型 | 描述 |
---|---|---|
match | 对象 | 要封装的多词条查询(可以是 prefix 、wildcard 、fuzzy 、range 或 regexp )。 |