【问题标题】:adding boost by field to a prefix and match_phrase_prefix queries将字段提升添加到前缀和 match_phrase_prefix 查询
【发布时间】:2017-03-23 19:40:53
【问题描述】:

我正在尝试为我的 es 查询中的不同字段添加分数提升,以便某个字段优先于另一个字段。

我的查询如下所示:

"query": {
    "bool": {
        "should": [{
            "prefix": {
               "title": "נפצ"
            }},{
            "match_phrase_prefix": {
               "sub_title": "נפצע קש"
            }
        }]
    }
}

由于某种原因,使用前缀和 match_phrase_prefix 似乎我无法添加分数助推器。

我想要实现的应该是这样的:

"query": {
    "bool": {
        "should": [{
            "prefix": {
               "title": "נפצ"
               "score": 2
            }
                   },{
            "prefix": {
               "sub_title": "נפ"
               "score": 1
            }
                  }]
    }
}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    [已编辑] 使用 boost 应该可以解决问题。根据documentation,这样的东西一定对你有用(虽然我自己没有尝试过):

    "query": {
        "bool": {
            "should": [{
                "prefix": {
                   "title": {
                      "value": "נפצ",
                      "boost": 2.0
                   }
                }},{
                "match_phrase_prefix": {
                   "sub_title": {
                      "query": "נפצע קש",
                      "boost": 1.0
                   }
                }
            }]
        }
    }
    

    【讨论】:

    • 感谢您的回复。我已经在 Sense add on chrome 中尝试过您的建议,但查询无法以这种方式工作。
    • 我修改了查询并编辑了答案:在 match_phrase_prefix 中,我将 'value' 替换为 'query' 并为我工作。它也适合你吗?
    • 非常感谢您的回答和快速编辑 - 我只能在周日告诉您它是否有效 :)
    • 现在可以使用了!非常感谢您的帮助。我对您的解决方案的唯一 cmets 是这些:我没有使用浮点数作为提升值我使用了 int。而且我没有使用对我不起作用的查询,但我使用了价值。
    猜你喜欢
    • 2022-01-06
    • 2012-11-01
    • 2015-03-10
    • 2015-02-14
    • 2021-12-22
    • 1970-01-01
    • 2013-10-29
    • 1970-01-01
    • 2014-01-05
    相关资源
    最近更新 更多