我正在尝试过滤 elasticsearch 的结果,它必须返回与搜索文本 80% 兼容的结果。
当我只对一个键执行此操作时,minimum_should_match
工作完美:
{
"size":30,
"from":930,
"query":{
"filtered":{
"query":{
"query_string":{
"default_field":"campo1",
"query":"portugues",
"minimum_should_match":"80%"
}
}
}
}
}
当我使用多个键进行搜索时,minimum_should_match
无法正常工作,返回具有 70% 兼容性的结果:
{
"size":30,
"from":123420,
"query":{
"filtered":{
"query":{
"query_string":{
"default_operator":"or",
"query":"portugues",
"fields":[
"campo1",
"campo2^5",
"campo3"
],
"minimum_should_match":"80%"
}
}
}
}
}
据我所知,我需要按键设置minimum_should_match
,但我不知道该怎么做。
如果有人可以帮助我这样做,那就太好了。
最佳答案
我需要使用 bool
和 multi_match
,这是正确的方法:
{
"size":"30",
"from":0,
"query":{
"filtered":{
"query":{
"bool":{
"should":[
{
"multi_match":{
"query":"portugues",
"type":"cross_fields",
"fields":[
"campo1^3",
"campo2^5",
"campo3^3"
],
"minimum_should_match":"80%"
}
}
]
}
}
}
}
}
关于search - 如何使用minimum_should_match 进行多字段搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22695749/