huha
huha

Reputation: 4255

Is it possible to remove the doc_count and more from Composite Aggregations

I use an ElasticSearch search request with composite aggregation in order to get a list of all different indexed values of one specific field. The result gives me all I need, but I don't need all that info contained.

Request:

{
    "aggs": {
        "my_buckets": {
            "composite": {
                "size": 10000,
                "sources": [{
                        "my_stoid": {
                            "terms": {
                                "field": "stoId"
                            }
                        }
                    }
                ]
            }
        }
    },
    "size": 0
}

Response:

{
    "took": 4,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 15,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },
    "aggregations": {
        "composite#my_buckets": {
            "after_key": {
                "my_stoid": "KV"
            },
            "buckets": [{
                    "key": {
                        "my_stoid": "1"
                    },
                    "doc_count": 5
                }, {
                    "key": {
                        "my_stoid": "2102"
                    },
                    "doc_count": 1
                }, {
                    "key": {
                        "my_stoid": "8000"
                    },
                    "doc_count": 1
                }, {
                    "key": {
                        "my_stoid": "9999"
                    },
                    "doc_count": 6
                }, {
                    "key": {
                        "my_stoid": "KB"
                    },
                    "doc_count": 1
                }, {
                    "key": {
                        "my_stoid": "KV"
                    },
                    "doc_count": 1
                }
            ]
        }
    }
}

I only need the values "1", "2102", "8000"... from the buckets. Like so:

    "buckets": ["1", "2102", "8000", "9999", "KB", "KV"]

Is there a way to achieve this?

Upvotes: 3

Views: 1385

Answers (1)

Sebastian
Sebastian

Reputation: 2550

A similar question in the Elasticsearch discussion forum got this answer:

The doc count is very low cost to calculate since it is just maintaining and incrementing a single long for each bucket. The cost of maintaining and updating sub aggregations for each bucket will be much more than this so it shouldn't significantly impact the performance of your aggregation request.

Upvotes: 0

Related Questions