我正在尝试设置一个匹配多个字段并满足以下要求的映射+查询:
我们的应用程序中有视频,我们为以下字段建立索引:localizedTitle
,localizedDescription
和localizedKeywords
示例视频:
{
"_id": "5b7d02e023366c0d85cb05d8",
"localizedTitle": [
{
"language": "en-GB",
"value": "Test String"
},
{
"language": "nl",
"value": "Test String - In het nederlands"
}
],
"localizedDescription": [
{
"language": "en-GB",
"value": "Test Description"
}
],
"localizedTags": [
{
"value": [
"tag in nederlands"
],
"language": "nl"
}
]
}
要求是:
标题为“测试字符串”的视频
如果用户搜索:应返回
我们仅在映射字段中使用'type': 'text'
,所以那里没有什么特别的。
这是我们当前使用的查询:
const query = {
from: (page * perPage),
size: perPage,
query: {
bool: {
filter,
must: {
multi_match: {
query: queryString,
fields: [
'localizedTitle.value',
'localizedDescription.value',
'localizedTags.value'
]
}
}
}
}
}
运行测试套件,我们最终满足了一些要求,但部分单词搜索无法正常工作:
GET /videos/search
Search
✓ should respond with a result when searched for: Test (69ms)
✓ should respond with a result when searched for: Test Test (60ms)
✓ should respond with a result when searched for: test test (58ms)
✓ should respond with a result when searched for: Test st (54ms)
✓ should respond with a result when searched for: st Test (56ms)
x) should respond with a result when searched for: Tes
x) should respond with a result when searched for: rin
x) should respond with a result when searched for: ing
x) should respond with a result when searched for: st st
我们尝试过的事情:
Fuzziness
,设置为AUTO
或numeric value (0 - 3)
进行测试,但这给我们不一致的测试结果,似乎导致了与上述相同的结果集。任何建议都值得欢迎