I want to achieve the equivalent of below SQL query in Elastic:
select BookId, PubDate, count(1)
from BookMessages
where BookId in (1,2)
group by BookId, PubDate
Hence I wrote the below query in C#
var searchresponse = client.Search<BookMessages>(s => s
.Query(q => q
.Bool(bq => bq
.Filter(fq => fq.Terms(t => t.Field(f => f.BookId).Terms(BookList)))))
.Aggregations(a => a
.Terms("group_by_book", ts => ts
.Field(f => f.BookId)
.Aggregations(a1 => a1
.DateHistogram("Date", dat => dat
.Field(f1 => f1.PubDate)
.Interval(DateInterval.Day)
.Format("dd/MM/yyyy")
)))));
I tried looping the output using following code, but wasn't able to loop any further.
foreach (var agg in searchresponse.Aggregations)
{
string key = agg.Key;
IAggregate objIAgg = agg.Value;
}
I can see the values in quickwatch but how do I fetch the values obtained?