# Get all documents by index name

**URL:** <https://discuss.elastic.co/t/get-all-documents-by-index-name/141924>\
**Category:** Kibana\
**Created:** [July 27, 2018, 11:07am UTC](https://discuss.elastic.co/t/get-all-documents-by-index-name/141924 "2018-07-27T11:07:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![asallemi](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@asallemi](https://discuss.elastic.co/u/asallemi)\
**Post date:** [July 27, 2018, 11:07am UTC](https://discuss.elastic.co/t/get-all-documents-by-index-name/141924/1 "2018-07-27T11:07:03Z")

</div>

Hello,

Which function should I use to get all documents by index name ?

**route.js:**

```
server.route({
    path: '/api/getAllDocuments/index/{name}',
    method: 'GET',
    handler(req, reply) {
      client.FUNCTION_NAME(req.params.name, function (err,response) {
        reply(response);
      });
    }
});

```

Thanks for advance.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 28, 2018, 11:30am UTC](https://discuss.elastic.co/t/get-all-documents-by-index-name/141924/2 "2018-07-28T11:30:48Z")

</div>

Use a [scroll query](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-scroll).

---

<div class="post-metadata">

**Author:** ![asallemi](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@asallemi](https://discuss.elastic.co/u/asallemi)\
**Post date:** [July 30, 2018, 2:16pm UTC](https://discuss.elastic.co/t/get-all-documents-by-index-name/141924/3 "2018-07-30T14:16:17Z")

</div>

Hello @Christian_Dahlqvist,  
I don't need a filter 😕 This is the only function I can use ?

```
const allTitles = [];
const responseQueue = [];

// start things off by searching, setting a scroll timeout, and pushing
// our first response into the queue to be processed
await client.search({
  index: 'myindex',
  scroll: '30s', // keep the search results "scrollable" for 30 seconds
  source: ['title'], // filter the source to only include the title field
  q: 'title:test'
}) ........

```

Thanks for advance .

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 30, 2018, 2:55pm UTC](https://discuss.elastic.co/t/get-all-documents-by-index-name/141924/4 "2018-07-30T14:55:59Z")

</div>

Scroll query is the best way to get large amounts of data with or without filters.

---

<div class="post-metadata">

**Author:** ![asallemi](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@asallemi](https://discuss.elastic.co/u/asallemi)\
**Post date:** [August 1, 2018, 7:10am UTC](https://discuss.elastic.co/t/get-all-documents-by-index-name/141924/5 "2018-08-01T07:10:10Z")

</div>

Hello @Christian_Dahlqvist,

I used scroll query without filter and this is my code:

```
server.route({
    path: '/api/indices_view/index/{name}',
    method: 'GET',
    handler(req, reply) {

      const responseQueue = [];
      const allHits = [];

      client.search({
        index: req.params.name,
        scroll: '30s'
      })

      while (responseQueue.length) {
        const response = responseQueue.shift();

        response.hits.hits.forEach(function (hit) {
          allHits.push(hit);
        });

        if (response.hits.total === allHits.length) {
          break
        }

        responseQueue.push(
          client.scroll({
            scrollId: response._scroll_id,
            scroll: '30s'
          })
        );
      }
    }
  });

```

I didn't get response in this case (like this route doesn't exist) 🙄 (Did I miss something here ?)

But if I use only the **client.search** :

```
client.search({
  index: req.params.name
}, function (err,response) {
   reply(response);
});

```

I got just the 10 first hits of the index selected, despite the console displays the right **total** of hits!!

 ![console](https://us1.discourse-cdn.com/elastic/original/3X/d/f/dfdbb131dc0dd6e1c5e5f00f8debb97ca32ed09e.png)

May you explain to me ?  
Thanks for advance @Christian_Dahlqvist 😉

---

<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:** [August 29, 2018, 7:10am UTC](https://discuss.elastic.co/t/get-all-documents-by-index-name/141924/6 "2018-08-29T07:10:18Z")

</div>

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