【问题标题】:MultiMatch query with Nest and Field Suffix带有嵌套和字段后缀的 MultiMatch 查询
【发布时间】:2015-06-15 18:43:10
【问题描述】:

使用 Elasticsearch 我有一个带有后缀的字段 - 带有 .english 后缀的字符串字段,上面带有英语分析器,如下图所示

...
"valueString": {
    "type": "string",
    "fields": {
        "english": {
             "type": "string",
             "analyzer": "english"
        }
    }
}
...

以下查询 sn-p 将无法编译,因为 ValueString 没有 English 属性。

...
sh => sh
    .Nested(n => n
        .Path(p => p.ScreenData)
            .Query(nq => nq
                .MultiMatch(mm => mm
                    .Query(searchPhrase)
                    .OnFields(
                        f => f.ScreenData.First().ValueString,
                        f => f.ScreenData.First().ValueString.english)
                    .Type(TextQueryType.BestFields)
                )
            )
        )...

有没有办法在查询时在 NEST 中强输入后缀,还是我必须使用魔术字符串?

【问题讨论】:

    标签: c# elasticsearch nest


    【解决方案1】:

    您是否尝试使用扩展方法Suffix

    这是修改查询的方法:

    ...
    .OnFields(
        f => f.ScreenData.First().ValueString,
        f => f.ScreenData.First().ValueString.Suffix("english"))
    .Type(TextQueryType.BestFields)
    ...
    

    希望对你有帮助。

    【讨论】:

    • 谢谢,工作愉快 - 不知道 - 当你知道怎么做时这么简单:-)
    猜你喜欢
    • 1970-01-01
    • 2019-09-29
    • 2018-02-02
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 1970-01-01
    • 2023-03-14
    相关资源
    最近更新 更多