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

别来无恙 提交于 2019-11-27 04:54:23

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/43038131/how-to-control-the-elasticsearch-aggregation-results-with-from-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!