# How to access the documents that is retrieved from the search aggregation nest bucket

**URL:** <https://discuss.elastic.co/t/how-to-access-the-documents-that-is-retrieved-from-the-search-aggregation-nest-bucket/76914>\
**Category:** Elasticsearch\
**Created:** [March 1, 2017, 5:10am UTC](https://discuss.elastic.co/t/how-to-access-the-documents-that-is-retrieved-from-the-search-aggregation-nest-bucket/76914 "2017-03-01T05:10:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nilanjana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nilanjana/32/15965_2.png) [@nilanjana](https://discuss.elastic.co/u/nilanjana)\
**Post date:** [March 1, 2017, 5:10am UTC](https://discuss.elastic.co/t/how-to-access-the-documents-that-is-retrieved-from-the-search-aggregation-nest-bucket/76914/1 "2017-03-01T05:10:37Z")

</div>

I have a query like this -

```
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

![](https://us1.discourse-cdn.com/elastic/original/2X/9/952256273e579565b6b49a542f14c512cb3d17f0.png)

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

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [March 2, 2017, 5:31am UTC](https://discuss.elastic.co/t/how-to-access-the-documents-that-is-retrieved-from-the-search-aggregation-nest-bucket/76914/2 "2017-03-02T05:31:46Z")

</div>

[I answered your question on Stack Overflow](http://stackoverflow.com/a/42526827/1831); I'll include here too 😄

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](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html)

```
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.](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html)

---

<div class="post-metadata">

**Author:** ![nilanjana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nilanjana/32/15965_2.png) [@nilanjana](https://discuss.elastic.co/u/nilanjana)\
**Post date:** [March 3, 2017, 4:44am UTC](https://discuss.elastic.co/t/how-to-access-the-documents-that-is-retrieved-from-the-search-aggregation-nest-bucket/76914/3 "2017-03-03T04:44:49Z")

</div>

Hi ross I am using nest version 1.4 . Could you tell me how do use that by keeping the nest version same as 1.4

---

<div class="post-metadata">

**Author:** ![nilanjana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nilanjana/32/15965_2.png) [@nilanjana](https://discuss.elastic.co/u/nilanjana)\
**Post date:** [March 3, 2017, 9:36am UTC](https://discuss.elastic.co/t/how-to-access-the-documents-that-is-retrieved-from-the-search-aggregation-nest-bucket/76914/4 "2017-03-03T09:36:29Z")

</div>

Hi Ross could you please have a look over this ?

> <https://stackoverflow.com/questions/42571457/extract-a-term-from-a-column-in-elasticsearch-nest>

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 31, 2017, 9:36am UTC](https://discuss.elastic.co/t/how-to-access-the-documents-that-is-retrieved-from-the-search-aggregation-nest-bucket/76914/5 "2017-03-31T09:36:36Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
