# Usage of Terms in Elasticsearch query?

**URL:** <https://discuss.elastic.co/t/usage-of-terms-in-elasticsearch-query/90605>\
**Category:** Elasticsearch\
**Created:** [June 23, 2017, 9:37am UTC](https://discuss.elastic.co/t/usage-of-terms-in-elasticsearch-query/90605 "2017-06-23T09:37:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yaswanth](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@Yaswanth](https://discuss.elastic.co/u/Yaswanth)\
**Post date:** [June 23, 2017, 9:37am UTC](https://discuss.elastic.co/t/usage-of-terms-in-elasticsearch-query/90605/1 "2017-06-23T09:37:38Z")

</div>

HI,

I had 20k documents ingested in ES 2.4.1 Cluster.

Usecase: I need to find all the documents in an index which has `book_ID = "value1"` and it should search for the documents whose `region_ID` falls in [Array of Values].

My Mappings:

```
"BookList": {
            "type": "nested",
            "include_in_parent": true,
            "properties": {
              "bookName": {
                "type": "string",
                "index": "not_analyzed"
              },
              "book_ID": {
                "type": "long"
              },
              "region_ID": {
                "type": "long"
              },
}

```

`NOTE: In 1 document i will have number of BookList's.`

The query i am sending:

`{"size":1332,"query":{"nested":{"query":{"bool":{"must":[{"term":{"BookList.book_ID":{"value":101639}}},{"terms":{"BookList.region_ID":[Passing Array of Values]}}]}},"path":"BookList"}}}`

I am facing error like `too_many_clauses: maxClauseCount is set to 1024` , and came to know that Lucene has a limit of 1024 terms in a query clause .

Questions:

1. How can i overcome it ?
2. Is it a good practice to send that many count in terms query?

Thanks

---

<div class="post-metadata">

**Author:** ![Ravi\_Shanker\_Reddy](https://avatars.discourse-cdn.com/v4/letter/r/a5b964/32.png) [@Ravi\_Shanker\_Reddy](https://discuss.elastic.co/u/Ravi_Shanker_Reddy)\
**Post date:** [June 23, 2017, 12:18pm UTC](https://discuss.elastic.co/t/usage-of-terms-in-elasticsearch-query/90605/2 "2017-06-23T12:18:06Z")

</div>

Its works for me. But I dont know its the best way or not.

```
PUT test/test/1
{
  "Books_list": [1,2,3,4,5,6]
}

```

Assuming you have all the book ids in the index document as mentioned above. Then use the list in the query.

```
GET BookList/nested/_search
{
    "query" : {
        bool":{
          "must": [
             {
               "terms": {
             	"book_ID": {
             	  "index": "test",
             	  "type": "test",
             	  "id": "1",
             	  "path": "Books_list"
             	}
               }
             }
	      ]
        }
    }
}

```

Now this query you will get all the documents which have the `"book_ID"`

---

<div class="post-metadata">

**Author:** ![Yaswanth](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@Yaswanth](https://discuss.elastic.co/u/Yaswanth)\
**Post date:** [June 23, 2017, 2:09pm UTC](https://discuss.elastic.co/t/usage-of-terms-in-elasticsearch-query/90605/3 "2017-06-23T14:09:57Z")

</div>

Thanks @Ravi_Shanker_Reddy

But in my query i am using book\_ID with respective to all the region\_ID in the array.  
In your query i can see only book\_ID .

Correct me if i am wrong

Thanks

---

<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 21, 2017, 2:10pm UTC](https://discuss.elastic.co/t/usage-of-terms-in-elasticsearch-query/90605/4 "2017-07-21T14:10:07Z")

</div>

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