【问题标题】:Elasticsearch.NET search records starts with a value in a string field (NEST)Elasticsearch.NET 搜索记录以字符串字段 (NEST) 中的值开头
【发布时间】:2020-11-22 21:23:47
【问题描述】:

我在搜索弹性时遇到问题。我使用 NEST 库进行搜索,并尝试获取以“GÖKDEMİR”开头的 customername 字段的记录(例如)

var response = await _elasticClient.SearchAsync<AccountAddressInfo>(p => p 
.Query(q => q
    .MatchPhrasePrefix(m => m
        .Field(f => f.CustomerName)
        .Query(filter.CustomerName)
        )
    ) 
.Size(101));

通过此搜索,我在customername 字段中获得了包含“GÖKDEMİR”的响应记录,但我想获得以“GÖKDEMİR”开头的字段。 我该怎么做。

【问题讨论】:

  • customerName 字段的映射是什么?
  • 映射用于属性名称,它在启动时配置。数据类型没有 mappimg

标签: string elasticsearch search .net-core nest


【解决方案1】:

如果您的customername 字段是term 类型,那么您可以尝试在使用MatchPhrasePrefix 的地方只使用Prefix,如下所示:

.Query(q => q
    .Prefix(m => m
        .Field(f => f.CustomerName)
        .Query(filter.CustomerName)
        )
    ) 
.Size(101));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-08
    • 2018-01-11
    • 2021-10-19
    • 1970-01-01
    • 2022-11-01
    • 1970-01-01
    • 2016-10-26
    相关资源
    最近更新 更多