# Get all of the documents for user in elastic enterprise search

**URL:** <https://discuss.elastic.co/t/get-all-of-the-documents-for-user-in-elastic-enterprise-search/361707>\
**Category:** Elastic Search\
**Created:** [June 19, 2024, 7:49am UTC](https://discuss.elastic.co/t/get-all-of-the-documents-for-user-in-elastic-enterprise-search/361707 "2024-06-19T07:49:23Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![CTO\_Servefast](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cto_servefast/32/131802_2.png) [@CTO\_Servefast](https://discuss.elastic.co/u/CTO_Servefast)\
**Post date:** [June 19, 2024, 7:49am UTC](https://discuss.elastic.co/t/get-all-of-the-documents-for-user-in-elastic-enterprise-search/361707/1 "2024-06-19T07:49:24Z")

</div>

I would like to get all of the documents for a user in elastic enterprise search using `@elastic/enterprise-search` npm package.

The only way i had some success was using `client.app.search()` using empty string for query but it seems unreliable and i am trying to look for another way to do it.

Elastic currently in use is 8.12.1 i can upgrade if needed

Thanks in advance

---

<div class="post-metadata">

**Author:** ![nfeekery](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nfeekery/32/117349_2.png) [@nfeekery](https://discuss.elastic.co/u/nfeekery)\
**Post date:** [June 19, 2024, 9:28am UTC](https://discuss.elastic.co/t/get-all-of-the-documents-for-user-in-elastic-enterprise-search/361707/2 "2024-06-19T09:28:39Z")

</div>

Hi @CTO_Servefast

> The only way i had some success was using `client.app.search()` using empty string for query but it seems unreliable

Can you expand on what makes it seem unreliable? The App Search search query should return all docs ordered by ID by default.

If docs are being added, deleted, updated, etc. during the search operation and that search result is paginated, there could be some inconsistencies in the results. You can resolve that by using [point in time API](https://www.elastic.co/guide/en/elasticsearch/reference/current/point-in-time-api.html), but to do this you'd need to use the [Elasticsearch JS client](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html) to send the requests to Elasticsearch instead of Enterprise Search.

---

<div class="post-metadata">

**Author:** ![CTO\_Servefast](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cto_servefast/32/131802_2.png) [@CTO\_Servefast](https://discuss.elastic.co/u/CTO_Servefast)\
**Post date:** [June 19, 2024, 10:07am UTC](https://discuss.elastic.co/t/get-all-of-the-documents-for-user-in-elastic-enterprise-search/361707/3 "2024-06-19T10:07:00Z")

</div>

> [@nfeekery](#):
>
> If docs are being added, deleted, updated, etc. during the search operation and that search result is paginated, there could be some inconsistencies in the results. You can resolve that by using [point in time API](https://www.elastic.co/guide/en/elasticsearch/reference/current/point-in-time-api.html), but to do this you'd need to use the [Elasticsearch JS client](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html) to send the requests to Elasticsearch instead of Enterprise Search.

What i was thinking actually is there an easier way to find all documents by property i es has `deleteByQuery` can we use that in conjuction to elastic enterprise search

---

<div class="post-metadata">

**Author:** ![nfeekery](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nfeekery/32/117349_2.png) [@nfeekery](https://discuss.elastic.co/u/nfeekery)\
**Post date:** [June 19, 2024, 10:40am UTC](https://discuss.elastic.co/t/get-all-of-the-documents-for-user-in-elastic-enterprise-search/361707/4 "2024-06-19T10:40:08Z")

</div>

Anything that is officially supported in the [HTTP Search API](https://www.elastic.co/guide/en/app-search/master/search.html) will work in the `body` field for `client.app.search()`. If there's nothing there that can be used to find the specific docs for a user based on your setup, then perhaps the Elasticsearch client will be more suited.

But first, going back to the original question:

> I would like to get all of the documents for a user in elastic enterprise search

How are the documents differentiated per user? Is this who uploaded the doc, or is there a user id associated to the doc, or something else?

---

<div class="post-metadata">

**Author:** ![CTO\_Servefast](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cto_servefast/32/131802_2.png) [@CTO\_Servefast](https://discuss.elastic.co/u/CTO_Servefast)\
**Post date:** [June 19, 2024, 10:56am UTC](https://discuss.elastic.co/t/get-all-of-the-documents-for-user-in-elastic-enterprise-search/361707/5 "2024-06-19T10:56:45Z")

</div>

@nfeekery there is userId defined in the document.

In regards to any Elasticsearch client i am having issues using `deleteByQuery` since i cant get the index of my engine that is used or maybe i am doing something wrong

---

<div class="post-metadata">

**Author:** ![nfeekery](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nfeekery/32/117349_2.png) [@nfeekery](https://discuss.elastic.co/u/nfeekery)\
**Post date:** [June 19, 2024, 12:44pm UTC](https://discuss.elastic.co/t/get-all-of-the-documents-for-user-in-elastic-enterprise-search/361707/6 "2024-06-19T12:44:27Z")

</div>

The index of the engine should be `.ent-search-engine-documents-<engine_name>`. Is that the index you're trying to use `deleteByQuery` against?

EDIT: if the engines are considerably older they may be `.app-search-<engine_name>`

---

<div class="post-metadata">

**Author:** ![nfeekery](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nfeekery/32/117349_2.png) [@nfeekery](https://discuss.elastic.co/u/nfeekery)\
**Post date:** [June 19, 2024, 12:48pm UTC](https://discuss.elastic.co/t/get-all-of-the-documents-for-user-in-elastic-enterprise-search/361707/7 "2024-06-19T12:48:31Z")

</div>

Also, you can use the [search explain API](https://www.elastic.co/guide/en/app-search/current/search-explain.html) which should show you the exact queries Enterprise Search will run against Elasticsearch. This will also show the index name for you.

---

<div class="post-metadata">

**Author:** ![CTO\_Servefast](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cto_servefast/32/131802_2.png) [@CTO\_Servefast](https://discuss.elastic.co/u/CTO_Servefast)\
**Post date:** [June 19, 2024, 3:47pm UTC](https://discuss.elastic.co/t/get-all-of-the-documents-for-user-in-elastic-enterprise-search/361707/8 "2024-06-19T15:47:50Z")

</div>

This is perfect thank you i will try it also it would be great if we could get index name for the engine

---

<div class="post-metadata">

**Author:** ![CTO\_Servefast](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cto_servefast/32/131802_2.png) [@CTO\_Servefast](https://discuss.elastic.co/u/CTO_Servefast)\
**Post date:** [June 20, 2024, 10:34am UTC](https://discuss.elastic.co/t/get-all-of-the-documents-for-user-in-elastic-enterprise-search/361707/9 "2024-06-20T10:34:43Z")

</div>

@nfeekery I have used it like this and it works really good. I have one follow up question it might be even for a separate thread.

If we are deleting thousands or even 10 of thousands of documents can it timeout and how can we know and what should we do in those cases should we split the query somehow into smaller batches.

Sample code:

```auto
    const index = `.ent-search-engine-documents-${engineName}`;
    const deleteResponse = await elasticSearchClient.deleteByQuery({
      index: index,
      query: {
        match: {
          user_id: userId,
        },
      },
    });

```

Best Regards

---

<div class="post-metadata">

**Author:** ![nfeekery](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nfeekery/32/117349_2.png) [@nfeekery](https://discuss.elastic.co/u/nfeekery)\
**Post date:** [June 21, 2024, 7:53am UTC](https://discuss.elastic.co/t/get-all-of-the-documents-for-user-in-elastic-enterprise-search/361707/10 "2024-06-21T07:53:00Z")

</div>

@CTO_Servefast glad to hear that it's working!

If you're concerned about timeouts for large payloads, you can run `deleteByQuery` asynchronously by using the flag `wait_for_completion=false` . The API will then return a task id that you can check the status on. [Here's the documentation for that.](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html#docs-delete-by-query-task-api)

---

<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 19, 2024, 7:53am UTC](https://discuss.elastic.co/t/get-all-of-the-documents-for-user-in-elastic-enterprise-search/361707/11 "2024-07-19T07:53:38Z")

</div>

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