elasticsearch - ElasticSearch 匹配多词关键字标记化字段
问题描述
我们有以下先决条件: 在 ES 上索引的具有tags字段的文档是字符串数组,例如: ['visa', 'credit card'] 我们要在tags字段上搜索这些文档。
要求:
- 如果文档有 标签:['visa', 'credit card'],我们只想在用户写了'visa'或'credit card'的情况下返回它,我们不希望接受'card','credit'和类似的部分,所以组合词必须完全匹配。
- 我们希望在单项和复合项的标签字段搜索中具有模糊性。
- 我们希望在标签字段上使用同义词。
所以我实现了:
"tags_analyzer": {
"filter": [
"lowercase",
"asciifolding",
"synonyms_expand",
],
"char_filter": [
"quotes",
"html_strip",
"ampersand",
"returns"
],
"type": "custom",
"tokenizer": "keyword"
},
"query_analyzer": {
"filter": [
"lowercase",
"my_asciifolding",
"shingle"
],
"char_filter": [
"quotes",
"html_strip",
"ampersand",
"returns"
],
"type": "custom",
"tokenizer": "standard"
},
"synonyms_expand": {
"ignore_case": "true",
"expand": "true",
"type": "synonym",
"synonyms": [
"visa, credit card",
"maestro, debit card"
],
"tokenizer": "keyword"
},
"shingle": {
"max_shingle_size": "3",
"min_shingle_size": "2",
"output_unigrams": "true",
"type": "shingle",
"filler_token": ""
}
在索引时间使用 tags_analyzer,在查询时间使用 query_analyzer。但是这个解决方案不适用于模糊复合术语。有谁知道为什么或有其他解决方案?
解决方案
推荐阅读
- javascript - 在带有 BrowserRouter 的 React JS 中使用字符串列表作为路径创建动态路由
- matlab - J1939 CAN 通讯,J1939 协议栈
- microsoft-graph-api - 未找到图表参与者 configureMixer
- python - 如果我有空值,如何总结年初至今?
- azure-devops - 如何在 Azure Devops 拉取请求中格式化状态检查响应
- excel - Excel 在线:带有结构化表引用的公式因 #REF 失败!使用 insertWorksheetsFromBase64 导入工作表时出错
- windows - 批处理:ECHO 输出汉字而不是数字
- angular - 什么是内容(参考)内容:TemplateRef
在角度? - python - 如何读取 hdf5 文件。并将它们绘制为图像
- c# - 如何添加具有主键的同一项目的多个日期