简体   繁体   中英

limit number of documents in aggregation elasticsearch

Query:

{
    "fields" : [],
    "size" : 0,
    "aggs" : {
        "top-terms" : {
            "terms": {
                "field" : "content",
                "size" : 10
            }
        }
    }
}

Response:

Array
(
    [took] => 20475
    [timed_out] => 
    [_shards] => Array
        (
            [total] => 5
            [successful] => 5
            [failed] => 0
        )

    [hits] => Array
        (
            [total] => 2652291
            [max_score] => 0
            [hits] => Array
                (
                )

        )

    [aggregations] => Array
        (
            [top-terms] => Array
                (
                    [doc_count_error_upper_bound] => 1214666
                    [sum_other_doc_count] => 831757781
                    [buckets] => Array
                        (
                            [0] => Array
                                (
                                    [key] => the
                                    [doc_count] => 2645615
                                )

                            [1] => Array
                                (
                                    [key] => to
                                    [doc_count] => 2638675
                                )

                            [2] => Array
                                (
                                    [key] => of
                                    [doc_count] => 2637099
                                )

                            [3] => Array
                                (
                                    [key] => and
                                    [doc_count] => 2633262
                                )

                            [4] => Array
                                (
                                    [key] => a
                                    [doc_count] => 2625627
                                )

                            [5] => Array
                                (
                                    [key] => in
                                    [doc_count] => 2621823
                                )

                            [6] => Array
                                (
                                    [key] => for
                                    [doc_count] => 2523026
                                )

                            [7] => Array
                                (
                                    [key] => is
                                    [doc_count] => 2480382
                                )

                            [8] => Array
                                (
                                    [key] => on
                                    [doc_count] => 2450387
                                )

                            [9] => Array
                                (
                                    [key] => that
                                    [doc_count] => 2447827
                                )

                        )

                )

        )

)

Aggregation on 2652291 documents ([total] => 2652291)

How can I limit number of documents to 1000?

size: 1000

does not work

"Ignore this text, i am just adding it here so stackoverflow lets me to post the question."

Got it working by adding limit filter

"filtered": {
    "filter": {
        "limit": {
           "value": 200
        }
    }
}

A limit filter limits the number of documents (per shard) to execute on. More info: https://www.elastic.co/guide/en/elasticsearch/reference/1.3/query-dsl-limit-filter.html

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