# Retrieving documents by ids in a static list using ElasticSearch

**URL:** <https://discuss.elastic.co/t/retrieving-documents-by-ids-in-a-static-list-using-elasticsearch/142495>\
**Category:** Elasticsearch\
**Created:** [August 1, 2018, 7:51am UTC](https://discuss.elastic.co/t/retrieving-documents-by-ids-in-a-static-list-using-elasticsearch/142495 "2018-08-01T07:51:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jainendra](https://avatars.discourse-cdn.com/v4/letter/j/59ef9b/32.png) [@jainendra](https://discuss.elastic.co/u/jainendra)\
**Post date:** [August 1, 2018, 7:51am UTC](https://discuss.elastic.co/t/retrieving-documents-by-ids-in-a-static-list-using-elasticsearch/142495/1 "2018-08-01T07:51:47Z")

</div>

I am having a hard time trying to solve a problem. The problem is something like this -

I have millions of documents in a type called `user` in ElasticSearch. There are two types of lists we create with these users.

1. Dynamic - Depending on the conditions the list members changes (for eg users which were created in last 30 days)  
2. Static - The list of users is hardcoded with CSV of user id

We query both types of the list from ElasticSearch. A dynamic list is easier to query as it has fewer conditions to evaluate and ES does that pretty well. But the problem is retrieving data from the static list as the query is a `terms` query which has performance issues when the number of user ids are larger.

Following is my ES query

```
{
    "query": {
        "terms" : { "userId" : ["userId1", "userId2"]}
    }
}

```

If I pass multiple userId (of the order of 50k) ES CPU spikes up and starts giving 504 error.

Is there any alternative to storing static list where the data could be retrieved quickly from ES?

---

<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:51am UTC](https://discuss.elastic.co/t/retrieving-documents-by-ids-in-a-static-list-using-elasticsearch/142495/2 "2018-08-29T07:51:48Z")

</div>

Closed on August 29, 2018, 7:51am UTC

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