Terms query routing optimization

My search is going to look something as below. For most cases the number of items in userId is expected to be between 100 to 200 atmost, although on some cases it may go up to 1000.

Is there anything to consider in general (either at the time of storage or the way i can define the mapping) that can help improve the performance of such query ?

I'm anticipating up to 20 million documents in the userdocs index.

GET userdocs/_search?pretty
  "query": {
    "terms": {
      "userId": [100, 200 ..... so on]
  "sort": [
      "timestamp": {
        "order": "desc"

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