# Query with a large set of ids (67000+ terms)

**URL:** <https://discuss.elastic.co/t/query-with-a-large-set-of-ids-67000-terms/244065>\
**Category:** Elasticsearch\
**Created:** [August 6, 2020, 4:28pm UTC](https://discuss.elastic.co/t/query-with-a-large-set-of-ids-67000-terms/244065 "2020-08-06T16:28:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vesli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vesli/32/73470_2.png) [@Vesli](https://discuss.elastic.co/u/Vesli)\
**Post date:** [August 6, 2020, 4:28pm UTC](https://discuss.elastic.co/t/query-with-a-large-set-of-ids-67000-terms/244065/1 "2020-08-06T16:28:32Z")

</div>

Hello,

I have a query for document that I want to filter by excluding a large set of ids (67000 terms) that I'm current doing as following:

```auto
    	query := map[string]interface{}{
		"query": map[string]interface{}{
			"bool": map[string]interface{}{
				"must_not": map[string]interface{}{
					"terms": map[string]interface{}{
						"uploadId": uploadIDs,
					},
				},
			},
		},
	}

```

uploadIDs is an array of string.

While fetching the ES documentation [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html#query-dsl-terms-lookup](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html#query-dsl-terms-lookup)

I see that there is a default limit in the number of terms you can pass of 65,536 terms.

And right now, while trying to process this large amount of must\_not I face this result:

`ES Search error {"status": "400 Bad Request", "type": "search_phase_execution_exception", "reason": "all shards failed"}`

which works fine if I use, let's say half the amount of uploadIDs.

My question:  
do I have to modify the `index.max_terms_count` or is there another solution to build the request?

I'm not entirely sure I understand the doc on this concern, any ideas would be great.

Many thanks,  
Jc

---

<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:** [September 3, 2020, 4:28pm UTC](https://discuss.elastic.co/t/query-with-a-large-set-of-ids-67000-terms/244065/2 "2020-09-03T16:28:37Z")

</div>

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