【问题标题】:Multimatch query with Fuzzy NEST - ElasticSearch使用模糊 NEST 进行多匹配查询 - ElasticSearch
【发布时间】:2020-07-14 11:12:10
【问题描述】:

我编写了以下查询来检查一个值的多个字段,它的工作原理:

    var searchResponse = client.Search<Document>(s => s
        .Query(q => q
        .MultiMatch(a => a
        .Fields(f => f
        .Field(p => p.Attachment.Content)
        .Field(p => p.FileName))
        .Query(queryValue))));

我会得到相同的结果(在 Attachment.Content 和 FileName 字段中搜索 queryValue),但使用模糊机制(例如,如果 queryValue 是“esting”,我也会得到文件名“testing”的结果)。

非常感谢! C# netCore 3.1

【问题讨论】:

    标签: c# asp.net elasticsearch .net-core nest


    【解决方案1】:

    在 Elasticsearch 中使用字符进行搜索。

    您可以对结果使用以下查询:(注意:必须阅读 cmets)

    //finds all strings starting with queryValue
    //string queryValue = queryValue + "*";
    
    //finds all strings containing queryValue
    string queryValue = "*" + queryValue + "*";
    
    //finds all strings ending with queryValue
    //string queryValue = "*" + queryValue;
            
    var searchResponse = client.Search<Document>(s => s
                    .Query(q => q
                    .QueryString(qs => qs
                    .Query(queryValue)
                    .Fields(f => f
                        .Field(Attachment.Content)//first field
                        .Field(FileName)//second field
                    ))));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      相关资源
      最近更新 更多