而在elasticsearch搜索galaxy mobiles
。 它会创建一个类似于下面的查询,因为galaxy
应该在mobiles
类别中进行搜索。'必须'和'应该'结合在布尔查询不起作用
{
"query": {
"bool": {
"should": [{
"multi_match": {
"query": "galaxy",
"fields": ["title", "product_specs", "category", "brand", "os"],
"operator": "and"
}
}, {
"multi_match": {
"query": "galaxy",
"fields": ["title", "product_specs", "category", "brand", "os"],
"type": "phrase_prefix"
}
}, {
"multi_match": {
"query": "galaxy",
"fields": ["title", "product_specs", "category", "brand", "os"],
"type": "phrase"
}
}],
"must": [{
"term": {
"category": "mobiles"
}
}]
}
}
}
只有must
条件的工作,should
条件不工作。 上述查询中是否有问题?
你说的不工作呢?你在期待什么? – femtoRgon
我想要在标题或其他字段中使用银河移动类别的产品。但它只给我手机类别 –