# How to manage large number of in clause values

**URL:** <https://discuss.elastic.co/t/how-to-manage-large-number-of-in-clause-values/110089>\
**Category:** Elasticsearch\
**Created:** [December 4, 2017, 5:48am UTC](https://discuss.elastic.co/t/how-to-manage-large-number-of-in-clause-values/110089 "2017-12-04T05:48:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nmathur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nmathur/32/21451_2.png) [@nmathur](https://discuss.elastic.co/u/nmathur)\
**Post date:** [December 4, 2017, 5:48am UTC](https://discuss.elastic.co/t/how-to-manage-large-number-of-in-clause-values/110089/1 "2017-12-04T05:48:30Z")

</div>

Hello,

I am performing in clause on elasticsearch NEST. But it is returning 400 if I am passing large number in clause values. In my case it is 1200 values. I am fetching large number of data and using scroll for that .. here I am sharing the code

```
 public IEnumerable<EmployeeDetail> GetDetails(IEnumerable<int> employeeIds)
        {
            var details = new List<EmployeeDetail>();

            var scanResults = ESClient().Search<EmployeeDetail>(s => s
                                .From(0)
                                .Size(10000)
                                .Index("myindex")
                                .Type("employeedetail")
                                .Query(q => q.Terms(t => t
                                              .Field(x => x.EmployeeId)
                                              .Terms(employeeIds))) //count for employeeIds can be 100, 500 or 1200 or more 
                                .Scroll("2s")
                              );

            if (!scanResults.IsValid)
            {
                throw new System.Web.HttpException(101, scanResults.DebugInformation);
            }

            details = scanResults.Documents.ToList();
            var scrolls = 0;
            var results = ESClient().Scroll<EmployeeDetail>("4s", scanResults.ScrollId);
            details.AddRange(results.Documents.ToList());

            while (results.Documents.Any())
            {
                results = ESClient().Scroll<EmployeeDetail>("4s", results.ScrollId);
                details.AddRange(results.Documents.ToList());
                scrolls++;
            }

            return details;
}

```

The query is working fine with 300+, 500+, but when number is 1000+ (1024) then I am getting this error:

> Invalid NEST response built from a unsuccessful low level call on POST: /myindex/employeedetail/\_search?scroll=2s # Audit trail of this API call: - [1] BadResponse: Node: [http://localhost:9200/](http://localhost:9200/) Took: 00:00:00.0924061 # ServerError: ServerError: 400Type: search\_phase\_execution\_exception Reason: "all shards failed" # OriginalException: System.Net.WebException: The remote server returned an error: (400) Bad Request. at System.Net.HttpWebRequest.GetResponse() at Elasticsearch.Net.HttpConnection.Request[TReturn](RequestData requestData) # Request: \<Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.\> # Response: \<Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.\>

Please share suggestions, how to handle this.

---

<div class="post-metadata">

**Author:** ![nmathur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nmathur/32/21451_2.png) [@nmathur](https://discuss.elastic.co/u/nmathur)\
**Post date:** [December 8, 2017, 12:24pm UTC](https://discuss.elastic.co/t/how-to-manage-large-number-of-in-clause-values/110089/2 "2017-12-08T12:24:44Z")

</div>

Anyone? ... I breaked the value list and applied terms like this .. this is working

```
.Query(q => q.Terms(t => t .Field(x => x.EmployeeId) .Terms(employeeIds.Skip(0).Take(1024))) ||
            q.Terms(t => t .Field(x => x.EmployeeId) .Terms(employeeIds.Skip(1024).Take(1024)))
)

```

Now I am not able to figure out the way to pass the query dynamically with 'or' ..

---

<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:** [January 5, 2018, 12:24pm UTC](https://discuss.elastic.co/t/how-to-manage-large-number-of-in-clause-values/110089/3 "2018-01-05T12:24:46Z")

</div>

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