假设我在ElasticSearch 6中有一个索引:
"mappings" : {
"pet" : {
"name" : {
"type" : "text"
},
"info" : {
"type" : "text"
},
"description" : {
"type" : "text"
}
}
}
我需要使用用户输入的相同输入字符串对所有字段执行全文搜索:“大灰狗”或“小可爱猫”。如何关联搜索那些包含来自输入的更多单词的单位。无论在哪里-名称或说明。我要那个单位:
{
"name" : "big",
"info" : "grey",
"description" : "dog"
}
得分高于单位:
{
"name" : "grey dog",
"info" : "dog dog grey dog",
"description" : "grey dog grey dog grey dog"
}
答案 0 :(得分:1)
如果您使用的是multiMatch
查询,则应将cross_field
类型与AND
运算符(see here)一起使用。
但是由于它将仅匹配包含所有术语的文档,因此您应该使用带有两个bool query
子句的should
,具有默认类型(也称为best_fields
)和默认{{ 1}}运算符,以及类型为OR
和运算符cross_field
的严格运算符。
通过此操作,将增强与所有字段匹配的文档,并继续显示仅与某些术语匹配的分数较低的文档:
类似:
AND