I am using ES 5. With Nest lib on C#.
I have two entities in my model, Contact and events. I have a requirement in which I have to get all contact than have more than N events (very similar to a having query on SQL). Contact are event parents so I can filter using a parent/child strategy.
I was able to get the aggregations for the contacts by I am not able to filter the contact by those aggreagations.
I did something like this:
var queryResult = client.Search<Contact>(s => s
.Index("contact*")
.Query(q => q
...
)
.Aggregations(a => a
.Children<Event>("filter_event", ca => ca.Aggregations(ca2 => ca2
.Filter("filter1", f => f.Filter(fq => fq.Term(t => t.Field(tf => tf.EventName).Value("Event1")))
.Aggregations(fa => fa
.Terms("filter1Contacts", v => v.Field(faf => faf.EventContactGuid).Size(int.MaxValue).MinimumDocumentCount(5))
)
)
)))
);
With this code I was able to get the aggregations for only those contacts with more than 5 events, but I did not find a way to filter my contact based on those aggregation results.
There is a way to do this in ES 5?
Contact
documents that have more than N childEvent
documents? – Russ Cam