elasticsearch - 如何在 Elasticsearch 中为精确搜索提供比语音搜索更高的分数?
问题描述
我目前正在使用 Elasticsearch 的语音分析器。我希望查询给完全匹配的分数比拼音匹配的分数更高。这是我正在使用的查询:
{
"query": {
"multi_match" : {
"query" : "Abhijeet",
"fields" : ["content", "title"]
}
},
"size": 10,
"_source": [ "title", "bench", "court", "id_" ],
"highlight": {
"fields" : {
"title" : {},
"content":{}
}
}
}
当我搜索 时Abhijeet
,最热门的查询是Abhijit
并且只是稍后才会Abhijeet
出现。我希望始终首先出现精确匹配,然后是语音匹配。这可以做到吗?
编辑:
映射
{
"courts_2": {
"mappings": {
"properties": {
"author": {
"type": "text",
"analyzer": "my_analyzer"
},
"bench": {
"type": "text",
"analyzer": "my_analyzer"
},
"citation": {
"type": "text"
},
"content": {
"type": "text",
"analyzer": "my_analyzer"
},
"court": {
"type": "text"
},
"date": {
"type": "text"
},
"id_": {
"type": "text"
},
"title": {
"type": "text",
"analyzer": "my_analyzer"
},
"verdict": {
"type": "text"
}
}
}
}
}
这是我用来设置语音分析器的代码:
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "standard",
"filter": [
"lowercase",
"my_metaphone"
]
}
},
"filter": {
"my_metaphone": {
"type": "phonetic",
"encoder": "metaphone",
"replace": true
}
}
}
}
},
"mappings": {
"properties": {
"author": {
"type": "text",
"analyzer": "my_analyzer"
},
"bench": {
"type": "text",
"analyzer": "my_analyzer"
},
"citation": {
"type": "text"
},
"content": {
"type": "text",
"analyzer": "my_analyzer"
},
"court": {
"type": "text"
},
"date": {
"type": "text"
},
"id_": {
"type": "text"
},
"title": {
"type": "text",
"analyzer": "my_analyzer"
},
"verdict": {
"type": "text"
}
}
}
}
现在,我只想查询title
andcontent
字段。在这里,我希望首先出现精确匹配,然后是语音匹配。
解决方案
一般的解决方法是:
- 使用-
bool
查询, - 在 must 子句中使用您的 ponectic 查询/查询,
- 和 should 子句中的非语音查询/查询
如果您将索引的映射和设置包含在您的问题中,我可以更新答案。
更新:解决方法
A. 扩展您的映射以使用多字段title
和content
:
"title": {
"type": "text",
"analyzer": "my_analyzer",
"fields" : {
"standard" : {
"type" : "text"
}
}
},
...
"content": {
"type": "text",
"analyzer": "my_analyzer"
"fields" : {
"standard" : {
"type" : "text"
}
}
},
B. 填充字段(例如,通过重新索引所有内容):
POST courts_2/_update_by_query
C. 调整您的查询以利用新引入的字段:
GET courts_2/_search
{
"_source": ["title","bench","court","id_"],
"size": 10,
"query": {
"bool": {
"must": {
"multi_match": {
"query": "Abhijeet",
"fields": ["title", "content"]
}
},
"should": {
"multi_match": {
"query": "Abhijeet",
"fields": ["title.standard", "content.standard"]
}
}
}
},
"highlight": {
"fields": {
"title": {},
"content": {}
}
}
}
推荐阅读
- netflix-archaius - 简单的 Netflix Archaius 动态配置示例不适用于本地文件
- c - -Werror 在 Ubuntu 终端中有什么作用?
- swift - 在这种情况下实现堆栈视图的最佳方式
- javascript - 按某些字母的大多数出现对数组进行排序
- android - 如何从对话框片段中设置片段中的文本?
- oracle - 如何更改数百个 Oracle 调度程序作业的状态
- ios - iOS String range(of:options:range:locale:) 确实适用于有效的正则表达式
- windows - 如何访问位于 Windows 上具有保留系统名称(如“CON”)的文件夹中的本地文件?
- javascript - 自动滚动到表格底部
- javascript - JS函数从后端调用给函数未定义的错误