c# - 未找到 Elasticsearch NEST Suggester 解析器
问题描述
我正在尝试利用 Elasticsearch 的“ Suggester ”功能。
使用短语、术语或完成,我总是得到以下错误变化。
unable to parse SuggestionBuilder with name [COMPLETION]: parser not found"
unable to parse SuggestionBuilder with name [TERM]: parser not found"
unable to parse SuggestionBuilder with name [PHRASE]: parser not found"
我尝试了多个 6.x NEST 版本,它们都有相同的问题。升级到 7.0alpha1 确实会改变错误,但似乎会导致无数其他问题,我宁愿不在生产中使用 alpha 库。
我目前正在关注本教程并将其应用于我现有的代码中:https ://github.com/elastic/elasticsearch-net-example/tree/6.x-codecomplete-netcore#part-6-suggestions
目前使用 NEST 6.1
模型:
public class SearchResult {
public SearchResult()
{
TitleSuggest = new CompletionField {Input = new List<string>(Title.Split(' '))};
}
public CompletionField TitleSuggest { get; set; }
//etc
}
索引方法:
public async Task<IActionResult> CreateIndex()
{
await _searchClient.CreateIndexAsync(SearchIndexName, indexSelector =>
indexSelector
.Mappings(mappingsDescriptor =>
mappingsDescriptor.Map<Models.SearchResult>(y => y.AutoMap().Properties(pr=>pr.Completion(c => c.Name(p => p.TitleSuggest)
))))
建议方法:
public async Task<ISearchResponse<SearchResult>> Suggest(string keyword)
{
return await _searchClient.SearchAsync<SearchResult>(
s =>
s.Suggest(ss => ss
.Completion("title", cs => cs
.Field(f => f.TitleSuggest)
.Prefix(keyword)
.Fuzzy(f => f
.Fuzziness(Fuzziness.Auto)
)
.Size(5))
}
我很难破译错误。似乎 NEST 库缺少 Suggester 解析器?任何帮助都会很棒,谢谢!
解决方案
试试这个:
var searchResponse = await _searchClient.SearchAsync<SearchResult>(s => s
.Index(ConfigurationManager.AppSettings.Get("index"))
.Type(ConfigurationManager.AppSettings.Get("indextype"))
.Suggest(su => su
.Completion("suggest", cs => cs
.Size(20)
.Field(f => f.TitleSuggest)
.Fuzzy(f => f
.Fuzziness(Fuzziness.Auto))
.Size(5))));
推荐阅读
- swagger - 如何合并多个 OpenAPI 规范?
- git - 如何在本地将工作分支 A 合并到新分支 B..?
- python - 将时间序列分组为不均匀的频率
- c - 消费者在数组已满之前不会启动
- python - 如何使用具有索引值的 numpy 数组将另一个 numpy 数组的元素设置为 0?
- c# - .NET Core Jwt 令牌在尝试访问授权区域时总是过期
- c# - 为什么 C# 导入仅在命名空间内有效
- python-3.8 - 如何在 Python 3.8 中为变量添加一个?
- google-cloud-platform - 将流数据从 API 提取到 Google Cloud 中的 Bigquery
- objective-c - 1:many:many 模型中的 NSArrayController 绑定细节