简体   繁体   English

Elasticsearch 限制多匹配查询的分数影响

[英]Elasticsearch limit score impact of multi-match query

I have a multi-match query which is matching against five different fields.我有一个多匹配查询,它匹配五个不同的字段。 I want to limit how much of an impact this multi-match query has on the overall query so that if for some reason, one of the fields has just been spammed with the search term(s), it doesn't get a massive score.我想限制这个多匹配查询对整体查询的影响有多大,这样如果由于某种原因,其中一个字段刚刚被搜索词填满了垃圾邮件,它就不会得到很高的分数. What I want is a decaying impact.我想要的是衰减的影响。 I have trawled through the documentation and I'm struggling to find a way to do this.我已经浏览了文档,并且正在努力寻找一种方法来做到这一点。 I have found the decay script functions docs ( https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/function-score-query-usage.html ) but they all seem to be specific to a single field which doesn't really help me as I want to apply it to a multi match query.我找到了衰减脚本函数文档( https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/function-score-query-usage.html )但它们似乎都是特定的到一个对我没有真正帮助的字段,因为我想将它应用于多匹配查询。

Here is the query I want to limit the impact of:这是我想限制影响的查询:

new MultiMatchQuery
{
    Type = TextQueryType.MostFields,
    Fields = Field<SearchableTour>(f => f.Name, 0.5)
        .And(Field<SearchableTour>(f => f.StartCity, 0.1))
        .And(Field<SearchableTour>(f => f.FinishCity, 0.1))
        .And(Field<SearchableTour>(f => f.Description, 0.05))
        .And(Field<SearchableTour>(f => f.ItineraryText, 0.01)),
    Query = searchText,
    Operator = Operator.And
}

The underlying data is not controlled by me and someone could theoretically just fill one of these fields with common search terms to artificially boost their result to the top.底层数据不受我控制,理论上有人可以用常见的搜索词填充这些字段之一,以人为地将其结果提升到顶部。 I want to prevent this but still allow these fields to have a limited impact.我想阻止这种情况,但仍然允许这些字段产生有限的影响。 There doesn't seem to be any concept of a "max score" which would allow me to restrict the combined score for these fields.似乎没有任何“最大分数”的概念可以让我限制这些字段的组合分数。

I think you're on the right path.我认为你走在正确的道路上。 You should be able to just plug your MultiMatchQuery into the query part of the link you provided, and then provide whatever score functions you want.您应该能够将 MultiMatchQuery 插入您提供的链接的查询部分,然后提供您想要的任何评分函数。 Note however that the decay functions provided are for numeric, date or geo_location fields, so you probably can't use those.但是请注意,提供的衰减函数用于数字、日期或地理位置字段,因此您可能无法使用它们。 What I would probably do is something like this:我可能会做的是这样的:

new FunctionScoreQuery()
{
    Query = new MultiMatchQuery{ ... },
    ScoreMode = FunctionScoreMode.Sum,
    Functions = new List<IScoreFunction>
    {
        new ScriptScoreFunction { Script = new InlineScript(##YourDecayFunction(_score)##) }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM