我认为最近添加的 (v6.1) terms_set query(Val 引用了他在评论中链接的问题)就是您想要的。
terms_set 与常规 terms 不同,它有一个参数来指定搜索词与字段中包含的词之间必须存在的最小匹配数。
给定:
PUT my_index/_doc/1
{
"values": ["living", "in a van", "down by the river"],
}
PUT my_index/_doc/2
{
"values": ["living", "in a house", "down by the river"],
}
terms 查询 ["living", "in a van", "down by the river"] 将返回给您两个文档:不好。 terms_set 配置为需要所有三个匹配项(脚本 params.num_terms 计算为 3)可以只为您提供匹配项:
GET my_index/_search
{
"query": {
"terms_set": {
"values": {
"terms": ["living", "in a van", "down by the river"],
"minimum_should_match_script": {
"source": "params.num_terms"
}
}
}
}
}
注意:虽然我在上面的示例中使用了minimum_should_match_script,但它并不是一个非常有效的模式。替代的minimum_should_match_field 是更好的方法,但在示例中使用它意味着需要更多的 PUT 来将必要的字段添加到文档中,所以我很简洁。