【发布时间】:2021-07-08 01:09:32
【问题描述】:
我有一个弹性搜索服务,当您输入文本输入然后填充表格时,它会获取该服务。对于所有字母数字值,但不是特殊字符(特别是连字符),搜索工作正常(返回过滤数据)。例如,对于国家/地区 Timor-Leste,如果我将 Timor 作为术语传入,我会得到结果,但只要添加连字符 (Timor-),就会得到一个空数组响应。
const queryService = {
search(tableName, field, term) {
// If there is no search term, run the wildcard search with 20 values
// for the smaller lists to be pre-populated, like "Gender"
return `
{
"size": ${term ? 200 : 20},
"query": {
"bool": {
"must": [
{
"match": {
"tablename": "${tableName}"
}
},
{
"wildcard": {
"${field}": {
"value": "${term ? `*${term.trim()}*` : '*'}",
"boost": 1.0,
"rewrite": "constant_score"
}
}
}
]
}
}
}
`;
},
};
有没有办法可以修改我的通配符请求以允许使用连字符?我在这里看到的另一个回复建议使用"analyze_wildcard": true,但没有奏效。我还尝试通过在每个带有.replace 的连字符前添加\ 来手动转义。
【问题讨论】:
标签: amazon-web-services elasticsearch wildcard