Usage of Terms in Elasticsearch query?

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

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"

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

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