I ran in to some issues whilst trying to use statistical facets on my documents in Elastic Search. This resulted in the following posts on the Elastic Search google group - see https://groups.google.com/forum/#!topic/elasticsearch/wNjrnAC_KOY. I tried to apply the recommendation in the answer about using Nested types with in the document to provide distinct sums on the collections property(see https://groups.google.com/forum/#!topic/elasticsearch/wNjrnAC_KOY)
That is I would have many instances of MyType with a collection of MyItem. Some collections of MyItem will have instances with matching amounts i.e. the first document could have two instances of myitem, both with an amount of 100. Without nested types I don't believe statistical facets will aggregate each amount as they're not unique.
So I've created a document structure (similar to below) and populated my index. Before populating my index I've used the following code in an effort to created a nested document.
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;}
}
However, when I run the following query via the nest api I don't get any results.
query.Index("pages")
.Type("page")
.From(0)
.Size(100)
.FacetStatistical("TotalAmount", x => x.Nested("donations")
.OnField("amount")));
More over I've also tried the following via the Chrome plugin PostMan :
{
"facets": {
"test": {
"statistical": {
"field": "amount"
},
"nested": "mycollection"
}
},
"size":0
}'
and get a response that notes :
"..facet nested path [mycollection] is not nested.."
Any thoughts on this would be great.
Tim