c# - Elasticsearch/Nest - 将 MatchPhrase 与 OnFieldsWithBoost 结合使用

标签 c# elasticsearch nest

在我今天的代码中,我正在做这样的搜索:

.Query(q => q.QueryString(qs => qs.Query(searchQuery).OnFieldsWithBoost(f => f.Add(b => b.MetaTitle, 5).Add(b => b.RawText, 1))))

我的问题是,如果我搜索像这样的短语,这会给我一个非常广泛的搜索范围。 “艳阳高照”。我试过在 RawText 上使用 MatchPhrase,而不是 QueryString,这有点管用。

问题是我仍然想在 MetaTitle 和 RawText 中搜索,并使用我现在使用的提升。

最佳答案

我不知道 Nest,但你想做的是使用 multi-match query of phrase type , 与 fields boost .

对 g**gle 的快速搜索为我提供了类似这样的增强部分语法:

.Query(q => q
    .MultiMatch(m => m
        .OnFieldsWithBoost(b => b
            .Add(o => o.MyField, 2.0)
            .Add(o => o.AnotherField, 3.0)
        )
        .Type(TextQueryType.Phrase)
        .Query("my query text")
    )
)

API 必须有某种类型的 type 参数来添加 phrase 类型。

编辑:快速查看 sources 后,我找到了一个Type方法,在上面添加。

关于c# - Elasticsearch/Nest - 将 MatchPhrase 与 OnFieldsWithBoost 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28169540/

相关文章:

c# - 如何在 C# for iOS 中设置颜色在固定背景图像上的透明度级别?

elasticsearch - 尝试使用jdbc River ElasticSearch插件进行批处理

c# - 从另一个线程更新控件的属性 (label.Text)

c# - FindByThumbprint - 证书存在但未找到

c# - HttpActionContext 唯一请求标识符

elasticsearch 得到太多结果,需要帮助过滤查询

elasticsearch - 我们如何在Elasticsearch中手动操作分数字段

c# - 模拟一个采用默认为 null 的可选参数的方法

elasticsearch - 使用nest获取elasticsearch中索引的字段列表

elasticsearch - 如何在Elasticsearch 7 NEST 7中设置 “max_result_window”