c# - Elasticsearch Nest客户端未应用提升

标签 c# elasticsearch nest

我正在调查一个搜索结果与预期不符的错误,并发现这是因为未应用增强功能。

该查询是使用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可以看出,这似乎是正确的,为什么它不起作用?

最佳答案

确实看起来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测试。

希望能有所帮助。

关于c# - Elasticsearch Nest客户端未应用提升,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58801023/

相关文章:

elasticsearch - 用于标记退回邮件的 Logstash grok 过滤器

python - django-haystack elasticsearch 作为后端和搜索引擎

php - 不能在同一必须过滤条件中包含一个字词和geo_distance_range

Android 上的 C# : Xamarin or Unity?

c# - 在同一装配空间中动态生成模块

c# - kinect c# 从保存的数据中绘制和移动骨架

elasticsearch - 使用EventStore和ElasticSearch实现CQRS

c# - ConcurrentBag 的正确用法是什么?

elasticsearch - 当数据之间有空格或破折号时,哪个分析器可以获取附加词的结果?

nest - 使用 Nest 索引多个文档的方法差异