Elasticsearch /巢 - 使用MatchPhrase与OnFieldsWithBoost [英] Elasticsearch/Nest - using MatchPhrase with OnFieldsWithBoost

查看:324
本文介绍了Elasticsearch /巢 - 使用MatchPhrase与OnFieldsWithBoost的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my code today I am doing a search like this:

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

我的问题是这给了我,如果我在寻找像一个短语非常广泛的搜索。 太阳普照。我在使用RawText尝试MatchPhrase,而不是查询字符串,这还挺工程。

My problem is this gives me a very wide search if I search on a phrase like. "The sun is shining". I have tried using MatchPhrase on RawText, instead of QueryString, and that kinda works.

问题是我还是想在这两个MetaTitle和RawText和我现在使用升压进行搜索。

The problem is I still want to search in both MetaTitle and RawText and with the boosting I am using now.

推荐答案

我不知道鸟巢,但你想要做的是使用的短语型多匹配查询,用的fields提振

I don't know Nest, but what you want to do is to use a multi-match query of phrase type, with fields boost.

一个快速对于g搜索** GLE给了我这样的语法部分提振:

A quick search on g**gle gave me a syntax like this for the boost part:

.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必须有某种类型参数添加语句键入这个

The API must have some sort of type parameter to add the phrase type to this.

修改:后快速浏览一下在<一个HREF =htt​​ps://github.com/elasticsearch/elasticsearch-net/blob/develop/src/Tests/Nest.Tests.Unit/QueryParsers/Queries/MultiMatchQueryTests.cs>来源中,我发现了一个类型方法,上述补充说。

Edit: after a quick look in the sources, I found a Type method, added above.

这篇关于Elasticsearch /巢 - 使用MatchPhrase与OnFieldsWithBoost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆