gpt4 book ai didi

c# - Elasticsearch 6.3 - 如何对分析的字段进行排序?

转载 作者:行者123 更新时间:2023-12-03 01:35:54 27 4
gpt4 key购买 nike

因此,我找到了旧版本 Elastic 的示例,但由于语法的变化,我无法将这些解决方案转换为 6.3 语法。

我有一个字段 ShowName (String),我已经应用了 N-Gram 分析器。问题是我还需要按该字段排序。在我添加分析器之前,我得到了 Keyword suffix 子属性并且能够轻松排序,但是,自从添加了分析器后,我现在无法访问该关键字子属性。

我尝试使用 [Text(Analyzer = "nGram_analyzer")]) 来装饰我的模型中的属性。和 Keyword属性,但是在创建索引时出现错误消息:

Multiple custom attributes of the same type found.



然后,我尝试在创建索引时在映射中显式添加两个字段(下面的代码),虽然这会创建两个字段,但我仍然无法按关键字后缀字段进行排序。谁能指出我哪里出错了?
var createIndexResponse = client.CreateIndex(shows, c => c
.Settings(s => s
.Analysis(a => a
.TokenFilters(t => t.NGram("nGram_filter", ng => ng.MinGram(3).MaxGram(10)))
.Analyzers(aa => aa
.Custom("nGram_analyzer", cc => cc
.Tokenizer("whitespace")
.Filters(nGramFilters1)
)
)
)
)
.Mappings(ms => ms
.Map<ShowElasticSearchModel>(m => m
.AutoMap<ShowElasticSearchModel>()
.Properties(p => p
.Text(t => t
.Name(n => n.ShowName)
.Analyzer("nGram_analyzer")
.Fields(fs => fs
.Text(tt => tt.Name(nn => nn.ShowName.Suffix("keyword")))
)
)
)
)
)
);

编辑:根据收到的答案,代码块的最终语法如下(现在在代码中包含多个多字段)。
var createIndexResponse = client.CreateIndex(shows, c => c
.Settings(s => s
.Analysis(a => a
.TokenFilters(t => t.NGram("nGram_filter", ng => ng.MinGram(3).MaxGram(10)))
.Analyzers(aa => aa
.Custom("nGram_analyzer", cc => cc
.Tokenizer("whitespace")
.Filters(nGramFilters1)
)
)
)
)
.Mappings(ms => ms
.Map<ShowElasticSearchModel>(m => m
.AutoMap<ShowElasticSearchModel>()
.Properties(p => p
.Text(t => t
.Name(n => n.ShowName)
.Analyzer("nGram_analyzer")
.Fields(ff => ff
.Keyword(k => k
.Name(n => n.ShowName.Suffix("keyword"))
)
)
)
.Text(t => t
.Name(n => n.Organisation)
.Analyzer("nGram_analyzer")
.Fields(ff => ff
.Keyword(k => k
.Name(n => n.Organisation.Suffix("keyword"))
)
)
)
.Text(t => t
.Name(n => n.Venues)
.Analyzer("nGram_analyzer")
.Fields(ff => ff
.Keyword(k => k
.Name(n => n.Venues.Suffix("keyword"))
)
)
)
)
)
)
);

最佳答案

String字段类型为 split keyword text 自 Elasticsearch 5.0 以来的类型。 Text字段不能用于排序,所以需要创建multi-field : 类型为 text用于全文搜索并输入 keyword用于聚合和排序。

但是在您的示例中,您创建了两个 text字段,并使用 keyword作为字段名称后缀而不是字段类型(据我所知 C# 语法)。

关于c# - Elasticsearch 6.3 - 如何对分析的字段进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52717011/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com