简体   繁体   中英

How to control the elasticsearch aggregation results with From / Size?

I have been trying to add pagination in elasticsearch term aggregation. In query we can add the pagination like,

 {
    "from": 0, // to add the start to control the pagination
    "size": 10,
    "query": { } 
 }

this is pretty clear, but when I want to add pagination to aggregation, I read a lot about it, but I couldn't find anything, My code looks like this,

{
  "from": 0,
  "size": 0,
  "aggs": {
    "group_by_name": {
      "terms": {
        "field": "name",
        "size": 20
      },
      "aggs": {
        "top_tag_hits": {
          "top_hits": {
            "size": 1
          }
        }
      }
    }
  }
}

Is there any way to create pagination with a function or any other suggestions?

Seems like you probably want partitions. From the docs:

Sometimes there are too many unique terms to process in a single request/response pair so it can be useful to break the analysis up into multiple requests. This can be achieved by grouping the field's values into a number of partitions at query-time and processing only one partition in each request.

Basically you add "include": { "partition": n, "num_partitions": x }, , where n is the page and x is the number of pages.

Unfortunately this feature was added fairly recently. If the tags can be believed on the GitHub Issue which spawned this feature, you'll need to be on at least Elasticsearch 5.2 or better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM