Required Paging in aggregation

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):

AWS OpenSearch 2.3

Describe the issue:

After filtering the data from index count of doc is 220000. There are distinct 99000 values when I apply aggregation on that. but Query return only 65535 rows as max.

“size”: 2,
“query”: {
“bool”: {
“must”: [
{“term”: {“Hits.AdminId”: “****” }},
{“match_phrase”: {“Hits.DistributionQueueID”: “00000000-0000-0000-0000-000000000000” }},
{“match_phrase”: {“Hits.SourceType.keyword”: “test” }}
]
}
},“aggs”: {
“data”: {
“terms”: { “field”: “Hits.Recipient.keyword”,“size”: 65536}
}
}

I want data with the help of pagination of 1000 record.

Configuration:

Relevant Logs or Screenshots:

You can do this with Composite Aggregation:

  "size": 0,
  "aggs": {
    "my_buckets": {
      "composite": {
        "size": 1000,
        "sources": [
          {
            "data": {
              "terms": { "field": "Hits.Recipient.keyword" }
            }
          }
        ]
      }
    }
  }

You will get non-null “after_key” in response, so you have to use that in “after” param in next call:

  "size": 0,
  "aggs": {
    "my_buckets": {
      "composite": {
        "size": 1000,
        "after": { ... },
        "sources": [
          {
            "data": {
              "terms": { "field": "Hits.Recipient.keyword" }
            }
          }
        ]
      }
    }
  }
1 Like

Thanks for the Solution.

But one more query is there any way to get data with limit and offset.

In my case, I am calling this data from Core API and return to the application. In application call implemented on limit and offset.

No, I don’t think so