【问题标题】:ElasticSearch Nest MatchPhrasePrefix Multiple FieldsElasticSearch Nest MatchPhrasePrefix 多个字段
【发布时间】:2017-03-13 17:58:05
【问题描述】:

我正在尝试使用 Nest C# 并链接到文本框进行搜索。我有多个要搜索的字段,但无法正常工作。

如果我在一个字段 [Title] 中搜索 "tit" 的部分文本以匹配具有 "title" 值的内容,这对我有用,但我还有 2 个字段我想添加到搜索中.

var searchResponse = client.Search<Search>(s => s
  .Query(q => q.MatchPhrasePrefix(m => m.Field(f=>f.Title).Query("tit").MaxExpansions(10)))
  .Index("myindex")
);

【问题讨论】:

    标签: c# elasticsearch nest


    【解决方案1】:

    您可以使用multi match phrase prefix query

    client.Search<Search>(s => s
        .Query(q => q
            .MultiMatch(mm => mm
                .Fields(f => f
                    .Field(ff => ff.Title)
                    .Field(ff => ff.Message)
                    .Field(ff => ff.Description)
                )
                .Type(TextQueryType.PhrasePrefix)
                .Query("tit")
                .MaxExpansions(10)
            )
        )
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-13
      • 1970-01-01
      • 2013-08-24
      • 1970-01-01
      • 2018-10-13
      • 1970-01-01
      • 1970-01-01
      • 2015-12-01
      相关资源
      最近更新 更多