4

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?

2
  • 1
    This thread might help: stackoverflow.com/a/59212580/4604579 (hint: use filter_path) Commented Aug 25, 2021 at 11:42
  • @Val By adding the query ?filter_path=aggregations.**.my_stoid to the request I only receive the "aggregations". And also the "doc_count" values are removed. It's not exactly what I wanted, but it reduces the response a lot. Many thanks :-) Commented Aug 26, 2021 at 5:25

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.