# Getting next 10k documents with AppSearch.list\_documents()

**URL:** https://discuss.elastic.co/t/getting-next-10k-documents-with-appsearch-list-documents/345216
**Category:** Elasticsearch
**Created:** [October 17, 2023, 1:40pm UTC](https://discuss.elastic.co/t/getting-next-10k-documents-with-appsearch-list-documents/345216 "2023-10-17T13:40:38Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![marc.schwarzschild](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@marc.schwarzschild](https://discuss.elastic.co/u/marc.schwarzschild)
#### Post date: [October 17, 2023, 1:40pm UTC](https://discuss.elastic.co/t/getting-next-10k-documents-with-appsearch-list-documents/345216/1 "2023-10-17T13:40:38Z")

</div>

Hi,  
I'm trying to get IDs for all our 300k+ documents. The AppSearch API has list\_documents which only lists 10k documents. Is there an argument I can use with it to get the next 10k documents?

I have searched and found that lots of other users are struggling with how to access all their documents. I even considered exporting/dumping all our data to my laptop and working outside [elastic.co](http://elastic.co). It seems like our data is held hostage with no apparent way to do this.

PLEASE ADVISE!

BTW, I'm doing this in Python.

Thank you,  
Marc

---

<div class="post-metadata">

### Author: ![sholzhauer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sholzhauer/32/110282_2.png) [@sholzhauer](https://discuss.elastic.co/u/sholzhauer)
#### Post date: [October 17, 2023, 2:09pm UTC](https://discuss.elastic.co/t/getting-next-10k-documents-with-appsearch-list-documents/345216/2 "2023-10-17T14:09:56Z")

</div>

I am assuming you are referencing [this documentation](https://www.elastic.co/guide/en/app-search/current/documents.html#documents-list)

In that case you should be able to use the `page` attribute in something like below to get all of your results.

```python
import requests

resp = requests.get(
    url="<your_es_endpoint>",
    auth=("<your_awesome_user>", "<your_extremely_secure_password>")
).json()

page = 0
results = []
while page != resp["meta"]["page"]["current"]:
    results += [res for res in resp["results"]]
    resp = requests.get(
        url="<your_es_endpoint>",
        auth=("<your_awesome_user>", "<your_extremely_secure_password>"),
        json={
            "size": 100,
            "page": f"{page + 1}"
        }
    ).json()
    page += 1

```

---

<div class="post-metadata">

### Author: ![marc.schwarzschild](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@marc.schwarzschild](https://discuss.elastic.co/u/marc.schwarzschild)
#### Post date: [October 17, 2023, 2:30pm UTC](https://discuss.elastic.co/t/getting-next-10k-documents-with-appsearch-list-documents/345216/3 "2023-10-17T14:30:23Z")

</div>

Thank you for the quick reply. What would the get be if I have the AppSearch host/key rather than endpoint/user/pw? I think host=endpoint.

---

<div class="post-metadata">

### Author: ![sholzhauer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sholzhauer/32/110282_2.png) [@sholzhauer](https://discuss.elastic.co/u/sholzhauer)
#### Post date: [October 17, 2023, 2:35pm UTC](https://discuss.elastic.co/t/getting-next-10k-documents-with-appsearch-list-documents/345216/4 "2023-10-17T14:35:26Z")

</div>

you mean the url (hostname) and an api key?

I think this should work (not sure)

```python
requests.get(
    url="<hostname>/api/as/v1/engines/,index>/documents/list",
    headers={
        "Authorization": "Bearer <apikey>"
    }

```

---

<div class="post-metadata">

### Author: ![marc.schwarzschild](https://avatars.discourse-cdn.com/v4/letter/m/5f9b8f/32.png) [@marc.schwarzschild](https://discuss.elastic.co/u/marc.schwarzschild)
#### Post date: [October 17, 2023, 2:51pm UTC](https://discuss.elastic.co/t/getting-next-10k-documents-with-appsearch-list-documents/345216/5 "2023-10-17T14:51:08Z")

</div>

Could this be done with the python Elasticsearch or AppSearch packages?

I successfully did a get() with a 200 return but it is just html with this comment at the end: "This Elastic installation has strict security requirements enabled that your current browser does not meet".

Once again, isn't there an easy way to get all our ids for 300k+ documents via Elasticsearch or AppSearch?

Thank you.

---

<div class="post-metadata">

### Author: ![sholzhauer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sholzhauer/32/110282_2.png) [@sholzhauer](https://discuss.elastic.co/u/sholzhauer)
#### Post date: [October 17, 2023, 5:14pm UTC](https://discuss.elastic.co/t/getting-next-10k-documents-with-appsearch-list-documents/345216/6 "2023-10-17T17:14:32Z")

</div>

You might need to add the json header:

```python
requests.get(
  url="<stuff>",
  headers={
    "Authorization": "Bearer <apikey>",
    "Content-Type": "application/json"
  }
)

```

If that doesn't work and there is a package, probably but I am not familiar with the module(s) and tend to just use the API. The API's are well build and it removes a component to just use it directly.

---

<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: [November 14, 2023, 5:15pm UTC](https://discuss.elastic.co/t/getting-next-10k-documents-with-appsearch-list-documents/345216/7 "2023-11-14T17:15:23Z")

</div>

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