【问题标题】:Elastic search Nest client not applying boost弹性搜索 Nest 客户端未应用提升
【发布时间】:2019-11-12 16:55:57
【问题描述】:

我正在调查搜索结果与预期不符的错误,并发现这是因为未应用提升。

查询是使用 NEST (6.6.0) 使用以下代码生成的:

queryContainer = new MultiMatchQuery
{
    Fuzziness = Fuzziness.Auto,
    Query = querystring,
    Type = TextQueryType.BestFields,
    Fields = Infer.Fields<RecipeSearchModel>(
        f1 => Infer.Field<RecipeSearchModel>(f => f.Title, 5),
        f2 => f2.Description,
        f3 => Infer.Field<RecipeSearchModel>(f => f.Ingredients, 3),
        f4 => f4.Method,
        f5 => Infer.Field<RecipeSearchModel>(f => f.Image.Alt, 4))
};

但是生成的查询没有应用任何提升。:

      "multi_match": {
        "fields": [
          "title",
          "description",
          "ingredients",
          "method",
          "image.alt"
        ],
        "fuzziness": "AUTO",
        "query": "chocolate",
        "type": "best_fields"
      }

从我从documentation 中得知,这似乎是正确的,为什么这不起作用?

【问题讨论】:

    标签: c# elasticsearch nest


    【解决方案1】:

    确实,boost 似乎在某处被忽略了,here 是 github 问题的链接。 现在,您可以尝试另一种语法:

    queryContainer = new MultiMatchQuery
    {
        Fuzziness = Fuzziness.Auto,
        Query = "query",
        Type = TextQueryType.BestFields,
        Fields = Infer.Fields<RecipeSearchModel>()
            .And(Infer.Field<RecipeSearchModel>(f => f.Title, 5))
            .And<RecipeSearchModel>(f => f.Description)
            .And(Infer.Field<RecipeSearchModel>(f => f.Ingredients, 3))
            .And<RecipeSearchModel>(f => f.Method)
            .And(Infer.Field<RecipeSearchModel>(f => f.Image.Alt, 4))
    };
    

    生成以下对 elasticsearch 的查询

    {
      "query": {
        "multi_match": {
          "fields": [
            "title^5",
            "description",
            "ingredients^3",
            "method",
            "image.alt^4"
          ],
          "fuzziness": "AUTO",
          "query": "query",
          "type": "best_fields"
        }
      }
    }
    

    使用 NEST 6.6.0 测试。

    希望对您有所帮助。

    【讨论】:

    • 非常感谢。你有 github 问题的链接吗?
    • 好的,给我 5 分钟完成它? 会更新答案。
    • 对不起。才注意到你几分钟前才回答!
    猜你喜欢
    • 2012-12-30
    • 2016-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多