# Limit in fetching documents through rest API

**URL:** <https://discuss.elastic.co/t/limit-in-fetching-documents-through-rest-api/263551>\
**Category:** Elasticsearch\
**Created:** [February 8, 2021, 7:12am UTC](https://discuss.elastic.co/t/limit-in-fetching-documents-through-rest-api/263551 "2021-02-08T07:12:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gauti](https://avatars.discourse-cdn.com/v4/letter/g/cdc98d/32.png) [@Gauti](https://discuss.elastic.co/u/Gauti)\
**Post date:** [February 8, 2021, 7:12am UTC](https://discuss.elastic.co/t/limit-in-fetching-documents-through-rest-api/263551/1 "2021-02-08T07:12:24Z")

</div>

Hi All,

I'm trying to fetch documents from elasticsearch using rest api but it looks like i can pull down only limited set of documents, below is the query i'm using and i'm getting very limited documents eventhough my index has more.

`http://itdashboard:9200/inc-ticket/_search`

I have tried the same in dev tools as well

`GET /inc_ticket/_search`

Is there any documents limit restriction applied by default?

Please advice.

Thanks  
Gautham

---

<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:** [February 8, 2021, 8:35am UTC](https://discuss.elastic.co/t/limit-in-fetching-documents-through-rest-api/263551/2 "2021-02-08T08:35:59Z")

</div>

You can use:

- the [`size` and `from` parameters](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html) to display by default up to 10000 records to your users. If you want to change this limit, you can change `index.max_result_window` setting but be aware of the consequences (ie memory).
- the [search after](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html) feature to do deep pagination.
- the [Scroll API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html) if you want to extract a resultset to be consumed by another tool later.

---

<div class="post-metadata">

**Author:** ![Gauti](https://avatars.discourse-cdn.com/v4/letter/g/cdc98d/32.png) [@Gauti](https://discuss.elastic.co/u/Gauti)\
**Post date:** [February 8, 2021, 8:51am UTC](https://discuss.elastic.co/t/limit-in-fetching-documents-through-rest-api/263551/3 "2021-02-08T08:51:11Z")

</div>

My main objective is to retrieve data for last 30 days, is this something achievable?

like the size  
[http://itdashboard:9200/inc-ticket/\_search?size=10000](http://itdashboard:9200/inc-ticket/_search?size=10000)

Can i add range  
[http://itdashboard:9200/inc-ticket/\_search?range=now-30d](http://itdashboard:9200/inc-ticket/_search?range=now-30d)

Is the above range type search is possible?

Thanks  
Gautham

---

<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:** [February 8, 2021, 10:32am UTC](https://discuss.elastic.co/t/limit-in-fetching-documents-through-rest-api/263551/4 "2021-02-08T10:32:10Z")

</div>

There are 2 questions here:

1. How I can select the last 30 days of records?
2. How I can retrieve all the documents matching this selection?

> [@Gauti](#):
>
> My main objective is to retrieve data for last 30 days, is this something achievable?

The answer is **YES but** :

If the number of records to retrieve is higher than 10000, you will need to check the links I shared in [my previous answer](https://discuss.elastic.co/t/limit-in-fetching-documents-through-rest-api/263551/2).  
If under 10000, you can use a range query with something like:

```auto
GET /_search/size=10000&q=date%3A%5Bnow-30d%2Fd%20TO%20now%2Fd%5D

```

This is the URL encoded version of this:

```auto
GET /_search/size=10000&q=date:[now-30d/d TO now/d]

```

But I always prefer using the QueryDSL:

```auto
GET /_search
{
  "size": 10000,
  "query": {
    "range": {
      "date": {
        "gte": "now-1d/d",
        "lte": "now/d"
      }
    }
  }
}

```

---

<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 8, 2021, 10:32am UTC](https://discuss.elastic.co/t/limit-in-fetching-documents-through-rest-api/263551/5 "2021-03-08T10:32:32Z")

</div>

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