How to Use pagination (size and from) in elastic search aggregation?

纵然是瞬间 提交于 2019-12-10 11:08:13

问题


How to Use pagination (size and from) in elasticsearch aggregation , I used Size and from in agreggition it,s throw exception for exmaple.
I wanna query like?

GET /index/nameorder/_search

{
    "size": 0,
    "query": {
        "filtered": {
            "query": {
                "bool": {
                    "must": [
                        {
                            "match": {
                                "projectId": "10057"
                            }
                        }
                    ]
                }
            },
            "filter": {
                "range": {
                    "purchasedDate": {
                        "from": "2012-02-05T00:00:00",
                        "to": "2015-02-11T23:59:59"
                    }
                }
            }
        }
    },
    "aggs": {
        "group_by_a": {
            "terms": {
                "field": "promocode",
                "size": 40,
                "from": 40
            },
            "aggs": {
                "TotalPrice": {
                    "sum": {
                        "field": "subtotalPrice"
                    }
                }
            }
        }
    }
}

回答1:


As of now , this feature is not supported.

There is a bug on this , but its still in discuss mode.

Issue - https://github.com/elasticsearch/elasticsearch/issues/4915




回答2:


In order to implement pagination on top of aggregation in Elasticsearch, you need to do as follows.

  1. Define the size of each batch.

  2. Run cardinality count

  3. Then according to cardinality define partition = (Cardinality count / size )(this size must be smaller than fetch size)

  4. now you can iterate over the partitions using partition filter - Please note size must be big enough cause the results are not equally splitted between the buckets.



来源:https://stackoverflow.com/questions/28456319/how-to-use-pagination-size-and-from-in-elastic-search-aggregation

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