使用 C# Nest 在 ElasticSearch 中按短语聚合
Aggregation by phrase in ElasticSearch using C# Nest
这是我的汇总:
return a =>
a.Terms("Group1", t => t.Field(ff => ff.ItemAttributeDesc1).
Aggregations(aa => aa.Terms("Value1", tt => tt.Field(fff => fff.SearchedFilterValue1))))
.Terms("Group2", t => t.Field(ff => ff.ItemAttributeDesc2).
Aggregations(aa => aa.Terms("Value2", tt => tt.Field(fff => fff.SearchedFilterValue2))))
.Terms("Group3", t => t.Field(ff => ff.ItemAttributeDesc3).
Aggregations(aa => aa.Terms("Value3", tt => tt.Field(fff => fff.SearchedFilterValue3))))
.Terms("Group4", t => t.Field(ff => ff.ItemAttributeDesc4).
Aggregations(aa => aa.Terms("Value4", tt => tt.Field(fff => fff.SearchedFilterValue4))))
.Terms("Group5", t => t.Field(ff => ff.ItemAttributeDesc5).
Aggregations(aa => aa.Terms("Value5", tt => tt.Field(fff => fff.SearchedFilterValue5))))
.Terms("Group6", t => t.Field(ff => ff.ItemAttributeDesc6).
Aggregations(aa => aa.Terms("Value6", tt => tt.Field(fff => fff.SearchedFilterValue6))))
.Terms("Group7", t => t.Field(ff => ff.ItemAttributeDesc7).
Aggregations(aa => aa.Terms("Value7", tt => tt.Field(fff => fff.SearchedFilterValue7))))
.Terms("Group8", t => t.Field(ff => ff.ItemAttributeDesc8).
Aggregations(aa => aa.Terms("Value8", tt => tt.Field(fff => fff.SearchedFilterValue8))))
.Terms("Brands", t => t.Field(ff => ff.VendorSearch).Size(60).Order(TermsOrder.TermAscending))
.Terms("Category", t => t.Field(ff => ff.MainSearch))
.Range("Price", ra => ra.Field(ff => ff.SalePrice)
.Ranges(
pr => pr.From(50).To(100),
pr => pr.From(100).To(250),
pr => pr.From(250).To(500),
pr => pr.From(500).To(750),
pr => pr.From(750).To(1000),
pr => pr.From(1000).To(1500),
pr => pr.From(1500).To(2000),
pr => pr.From(2000).To(2500),
pr => pr.From(2500).To(3000),
pr => pr.From(3000).To(3500),
pr => pr.From(3500)));
除一件事外,一切正常。我必须按完全匹配进行汇总。例如,如果我有术语字段 "Field"(一个词),它工作正常。但是,如果该术语包含多个单词(或具有特定符号),则它不起作用。不起作用,因为用空格和符号弹性拆分短语。我需要 100% 匹配这里。谁能帮我解决这个问题?
发生这种情况是因为您正在聚合的字段被映射为分析字符串,这是字符串类型的默认映射,要解决此问题,请将您正在聚合的相关字段映射为 type: string
和 index: not_analyzed
查看有关 analyzed strings
的更多信息
这是我的汇总:
return a =>
a.Terms("Group1", t => t.Field(ff => ff.ItemAttributeDesc1).
Aggregations(aa => aa.Terms("Value1", tt => tt.Field(fff => fff.SearchedFilterValue1))))
.Terms("Group2", t => t.Field(ff => ff.ItemAttributeDesc2).
Aggregations(aa => aa.Terms("Value2", tt => tt.Field(fff => fff.SearchedFilterValue2))))
.Terms("Group3", t => t.Field(ff => ff.ItemAttributeDesc3).
Aggregations(aa => aa.Terms("Value3", tt => tt.Field(fff => fff.SearchedFilterValue3))))
.Terms("Group4", t => t.Field(ff => ff.ItemAttributeDesc4).
Aggregations(aa => aa.Terms("Value4", tt => tt.Field(fff => fff.SearchedFilterValue4))))
.Terms("Group5", t => t.Field(ff => ff.ItemAttributeDesc5).
Aggregations(aa => aa.Terms("Value5", tt => tt.Field(fff => fff.SearchedFilterValue5))))
.Terms("Group6", t => t.Field(ff => ff.ItemAttributeDesc6).
Aggregations(aa => aa.Terms("Value6", tt => tt.Field(fff => fff.SearchedFilterValue6))))
.Terms("Group7", t => t.Field(ff => ff.ItemAttributeDesc7).
Aggregations(aa => aa.Terms("Value7", tt => tt.Field(fff => fff.SearchedFilterValue7))))
.Terms("Group8", t => t.Field(ff => ff.ItemAttributeDesc8).
Aggregations(aa => aa.Terms("Value8", tt => tt.Field(fff => fff.SearchedFilterValue8))))
.Terms("Brands", t => t.Field(ff => ff.VendorSearch).Size(60).Order(TermsOrder.TermAscending))
.Terms("Category", t => t.Field(ff => ff.MainSearch))
.Range("Price", ra => ra.Field(ff => ff.SalePrice)
.Ranges(
pr => pr.From(50).To(100),
pr => pr.From(100).To(250),
pr => pr.From(250).To(500),
pr => pr.From(500).To(750),
pr => pr.From(750).To(1000),
pr => pr.From(1000).To(1500),
pr => pr.From(1500).To(2000),
pr => pr.From(2000).To(2500),
pr => pr.From(2500).To(3000),
pr => pr.From(3000).To(3500),
pr => pr.From(3500)));
除一件事外,一切正常。我必须按完全匹配进行汇总。例如,如果我有术语字段 "Field"(一个词),它工作正常。但是,如果该术语包含多个单词(或具有特定符号),则它不起作用。不起作用,因为用空格和符号弹性拆分短语。我需要 100% 匹配这里。谁能帮我解决这个问题?
发生这种情况是因为您正在聚合的字段被映射为分析字符串,这是字符串类型的默认映射,要解决此问题,请将您正在聚合的相关字段映射为 type: string
和 index: not_analyzed
查看有关 analyzed strings
的更多信息