# API Requesting all documents in a certain range

**URL:** <https://discuss.elastic.co/t/api-requesting-all-documents-in-a-certain-range/115404>\
**Category:** Elasticsearch\
**Created:** [January 13, 2018, 12:45pm UTC](https://discuss.elastic.co/t/api-requesting-all-documents-in-a-certain-range/115404 "2018-01-13T12:45:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![THUND3R](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@THUND3R](https://discuss.elastic.co/u/THUND3R)\
**Post date:** [January 13, 2018, 12:45pm UTC](https://discuss.elastic.co/t/api-requesting-all-documents-in-a-certain-range/115404/1 "2018-01-13T12:45:16Z")

</div>

Good afternoon!  
How to correctly make a request to the elastic to get all the documents that fit the query for example: `"query": { "bool": { "must": [{ "exists": { "field": "somefield" } }], "filter": [{ "range": { "timestamp": { "gte": "2018-01-10 15:20:47.381" } } }] } }, "_source": ["somefield", "source"] }`  
?

If I make a simple query, it prints out only with the default "size" value of 10, and how to do it to display all the values if you do not know the number of documents in advance?  
Thanks.

---

<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:** [January 13, 2018, 1:38pm UTC](https://discuss.elastic.co/t/api-requesting-all-documents-in-a-certain-range/115404/2 "2018-01-13T13:38:23Z")

</div>

If your goal is to export thousands of records you can use the scrolll API which is built for that.

---

<div class="post-metadata">

**Author:** ![THUND3R](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@THUND3R](https://discuss.elastic.co/u/THUND3R)\
**Post date:** [January 13, 2018, 3:35pm UTC](https://discuss.elastic.co/t/api-requesting-all-documents-in-a-certain-range/115404/3 "2018-01-13T15:35:43Z")

</div>

Thank you for your advice!  
It fits perfectly! Will be using helpers from elasticsearch-py module ))

To not create a new post - I`ll ask again here... In what order to make a query in this situation: I want make a query by the presence of a certain field, but for a certain period, and then aggregate these data for example by source. Is this wright?`"query": { "bool": { "must": [{"exists": {"field": "some\_field"} }], "filter": [{ "range": {timestamp": {"gte": "2018-01-10 15:20:47.381"}, "aggregations": {"the\_name": {"terms": {"field": "source"}}}  
Thank you!

---

<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:** [January 13, 2018, 3:52pm UTC](https://discuss.elastic.co/t/api-requesting-all-documents-in-a-certain-range/115404/4 "2018-01-13T15:52:17Z")

</div>

I'd put also the exists in the filter part. So probably something like:

```auto
{
   "query":{
      "bool":{
         "filter":[
            {
               "exists":{
                  "field":"some_field"
               }
            },
            {
               "range":{
                  "timestamp":{
                     "gte":"2018-01-10 15:20:47.381"
                  }
               }
            }
         ]
      }
   },
   "aggregations":{
      "the_name":{
         "terms":{
            "field":"source"
         }
      }
   }
}

```

---

<div class="post-metadata">

**Author:** ![THUND3R](https://avatars.discourse-cdn.com/v4/letter/t/4af34b/32.png) [@THUND3R](https://discuss.elastic.co/u/THUND3R)\
**Post date:** [January 13, 2018, 8:07pm UTC](https://discuss.elastic.co/t/api-requesting-all-documents-in-a-certain-range/115404/5 "2018-01-13T20:07:14Z")

</div>

Thank you very much!!!

---

<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:** [February 10, 2018, 8:07pm UTC](https://discuss.elastic.co/t/api-requesting-all-documents-in-a-certain-range/115404/6 "2018-02-10T20:07:27Z")

</div>

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