elasticsearch - Elasticsearch:按最多的应该匹配进行排名
问题描述
我有一个索引的职位描述字段。我正在尝试按匹配数对结果进行排名或排序。
例如,我正在寻找:
- 友谊赛
- 诚实的个性
- 高超的交流技巧
匹配次数最多的记录将排名最高。我在这里尝试了建议https://stackoverflow.com/a/45319822/2445717但没有按我的预期工作。
以下是我当前的查询:
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"match": {
"job_description": {
"query": "friendly",
"operator": "and"
}
}
},
{
"match": {
"job_description": {
"query": "honest personality",
"operator": "and"
}
}
},
{
"match": {
"job_description": {
"query": "excellent communication skills",
"operator": "and"
}
}
}
]
}
}
]
}
}
}
解决方案
match_query
&minimum_should_match
成功了。
发布示例代码以防有人需要它。
{
"query": {
"bool": {
"should": [
{
"match_query": {
"job_description": {
"query": "friendly",
"boost": 1
}
}
},
{
"match_query": {
"job_description": {
"query": "honest personality",
"boost": 1
}
}
},
{
"match_query": {
"job_description": {
"query": "excellent communication skills",
"boost": 1
}
}
}
],
"minimum_should_match": 1
}
}
}
推荐阅读
- wpf - 为什么两个 Transform 不能与 Helix Toolkit 对象一起使用
- dart - 如何在每个特定页面上添加文本?
- pyomo - Pyomo:重新定义集合
- google-chrome - Chrome 扩展程序有关于 UTF-8 的 content.js 错误
- python - 如何搜索一个列表并查看所有这些项目是否在第二个列表中,然后打印(如果有)所有缺失的元素以及有多少?
- c# - 如何在 MVC 中使用 DB First Approach 从连接表中获取数据
- directx - 使用 DirectX 渲染两个元素时的时序不同步
- scala - Spark DataFrame 缓存不断增长
- java - 使用Java8排序并检查数字是否连续
- reactjs - ReactStrap NavLinks 在通过组件呈现时被破坏