我在尝试在 Elastic Search 中的文档上使用统计方面时遇到了一些问题。这导致 Elastic Search google 群组上出现以下帖子 - 请参阅https://groups.google.com/forum/#!topic/elasticsearch/wNjrnAC_KOY。我尝试应用关于在文档中使用嵌套类型的答案中的建议,以在集合属性上提供不同的总和(请参阅https://groups.google.com/forum/#!topic/elasticsearch/wNjrnAC_KOY)
也就是说,我将拥有许多带有 MyItem 集合的 MyType 实例。 MyItem 的某些集合将具有匹配金额的实例,即第一个文档可能有两个 myitem 实例,金额均为 100。如果没有嵌套类型,我不相信统计方面会聚合每个金额,因为它们不是唯一的。
因此,我创建了一个文档结构(类似于下面)并填充了我的索引。在填充索引之前,我使用以下代码来创建嵌套文档。
client.MapFromAttributes<Page>();
[ElasticType(Name="page", DateDetection = true, NumericDetection = true, SearchAnalyzer = "standard",IndexAnalyzer = "standard")]
public class MyType
{
public int TypeId { get; set; }
public string Name { get; set; }
public ANotherType AnotherProperty { get; set; }
public DateTime Created { get; set; }
[ElasticProperty(Type = FieldType.nested, Name="mycollection")]
public List<MyItem> MyItems { get;
}
public class MyItem
{
public decimal Amount {get;set;}
}
但是,当我通过 Nest api 运行以下查询时,我没有得到任何结果。
query.Index("pages")
.Type("page")
.From(0)
.Size(100)
.FacetStatistical("TotalAmount", x => x.Nested("donations")
.OnField("amount")));
此外,我还通过 Chrome 插件 PostMan 尝试了以下操作:
{
"facets": {
"test": {
"statistical": {
"field": "amount"
},
"nested": "mycollection"
}
},
"size":0
}'
并得到回复,其中注明:
“..facet 嵌套路径 [mycollection] 未嵌套..”
对此的任何想法都会很棒。
Tim