var result = clientConnection.Search<dynamic>(s => s
.Index(indexname)
.Type(typename)
.Aggregations(a => a
.DateRange(fieldvalue, d => d
.Field(fieldname)
.Ranges(
r => r.To("2016-03-30T19:40:50+00:00"),
r => r.From("2016-03-15T19:40:50+00:00")
)
)
)
);
var agg = result.Aggs.DateRange("L2");
But this gives me 2 nest buckets like this
This gives me only the document count. But I need to see the values inside the document. How do I retrieve the values in the document ? I used Nest.BucketItem but I am not able to retrieve it.
Also I can see that there are 2 buckets. Why not 1? Please suggest
If you're after the actual documents, then a query to get the documents is probably what you need, as opposed to an aggregation. You can issue multiple queries in one request with Multi Search API
var indexname = "index-name";
var typename = "type-name";
var fieldname = "field-name";
var result = client.MultiSearch(ms => ms
.Index(indexname)
.Type(typename)
.Search<dynamic>("search1", s => s
.Query(q => +q
.DateRange(r => r
.Field(fieldname)
.LessThan("2016-03-30T19:40:50+00:00")
)
)
)
.Search<dynamic>("search2", s => s
.Query(q => +q
.DateRange(r => r
.Field(fieldname)
.GreaterThan("2016-03-15T19:40:50+00:00")
)
)
)
);
var search1Documents = result.GetResponse<dynamic>("search1").Documents;
var search2Documents = result.GetResponse<dynamic>("search2").Documents;
This will return you the first 10 documents that match, for each of the queries. You can use .From() and .Size() on each search to paginate results, and if you need to fetch a lot of documents, consider using the Scroll API.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.