# Elasticsearch search query to retrieve all records NEST

**URL:** <https://discuss.elastic.co/t/elasticsearch-search-query-to-retrieve-all-records-nest/52562>\
**Category:** Elasticsearch\
**Created:** [June 13, 2016, 5:15am UTC](https://discuss.elastic.co/t/elasticsearch-search-query-to-retrieve-all-records-nest/52562 "2016-06-13T05:15:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ASN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/asn/32/10535_2.png) [@ASN](https://discuss.elastic.co/u/ASN)\
**Post date:** [June 13, 2016, 5:15am UTC](https://discuss.elastic.co/t/elasticsearch-search-query-to-retrieve-all-records-nest/52562/1 "2016-06-13T05:15:10Z")

</div>

I have few documents in a folder and I want to check if all the documents in this folder are indexed or not. To do so, for each document name in the folder, I would like to run through a loop for the documents indexed in ES and compare. So I want to retrieve all the documents.

There are few other possible duplicates of the same question in SO, but they didn't help me as the documentation has changed .(there is nothing about scan in the current documentation)

I tried using `client.search<T>()` . But as per the documentation, a default number of 10 results are retrieved. I would like to get all the records without mentioning the size of records ? (Because the size of the index changes)

Or is it possible to get the size of the index first and then send this number as input to the size to get all the documents and loop through?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 13, 2016, 5:56am UTC](https://discuss.elastic.co/t/elasticsearch-search-query-to-retrieve-all-records-nest/52562/2 "2016-06-13T05:56:33Z")

</div>

Use scroll API for this.

---

<div class="post-metadata">

**Author:** ![ASN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/asn/32/10535_2.png) [@ASN](https://discuss.elastic.co/u/ASN)\
**Post date:** [June 13, 2016, 8:03am UTC](https://discuss.elastic.co/t/elasticsearch-search-query-to-retrieve-all-records-nest/52562/3 "2016-06-13T08:03:45Z")

</div>

Thanks David.

Is there any tutorial or sample example in NEST available for the same? Because I tried to do using scroll. Once I get a scrollId, how do I run another search query using the scrollId?

for eg: `var response = client.Search<Document>(s=>s.Scroll("2m"));` --\> Retrieves only 10 documents

from this response, I got `response.scrollId: "Ascsjdbgkjabgkakjfgsadhvkjag"`

How do I proceed from here? I just want to add all the filenames in a list.

TIA

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 13, 2016, 8:18am UTC](https://discuss.elastic.co/t/elasticsearch-search-query-to-retrieve-all-records-nest/52562/4 "2016-06-13T08:18:00Z")

</div>

I don't know with Nest.

Using REST is like this: [https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-request-scroll.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-request-scroll.html)

---

<div class="post-metadata">

**Author:** ![ASN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/asn/32/10535_2.png) [@ASN](https://discuss.elastic.co/u/ASN)\
**Post date:** [June 13, 2016, 8:20am UTC](https://discuss.elastic.co/t/elasticsearch-search-query-to-retrieve-all-records-nest/52562/5 "2016-06-13T08:20:06Z")

</div>

Thanks David.  
I tried to write in NEST using this documentation only but couldn't. So asked for your help.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 13, 2016, 10:41am UTC](https://discuss.elastic.co/t/elasticsearch-search-query-to-retrieve-all-records-nest/52562/6 "2016-06-13T10:41:12Z")

</div>

Better chance in #development list?

---

<div class="post-metadata">

**Author:** ![ASN](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/asn/32/10535_2.png) [@ASN](https://discuss.elastic.co/u/ASN)\
**Post date:** [June 14, 2016, 1:48am UTC](https://discuss.elastic.co/t/elasticsearch-search-query-to-retrieve-all-records-nest/52562/7 "2016-06-14T01:48:59Z")

</div>

Thanks David. Got the solution.

```
List<string> indexedList = new List<string>();
var scanResults = client.Search<ClassName>(s => s
                .From(0)
                .Size(2000)
                .MatchAll()
                .Fields(f=>f.Field(fi=>fi.propertyName)) //I used field to get only the value I needed rather than getting the whole document
                .SearchType(Elasticsearch.Net.SearchType.Scan)
                .Scroll("5m")
            );

        var results = client.Scroll<ClassName>("10m", scanResults.ScrollId);
        while (results.Documents.Any())
        {
            foreach(var doc in results.Fields)
            {
                indexedList.Add(doc.Value<string>("propertyName"));
            }

            results = client.Scroll<ClassName>("10m", results.ScrollId);
        }
```

---

<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:** [July 5, 2017, 10:44pm UTC](https://discuss.elastic.co/t/elasticsearch-search-query-to-retrieve-all-records-nest/52562/8 "2017-07-05T22:44:09Z")

</div>


