Aggs percentage doc_count

Viewed 18

So I know my total hits are 182 documents

"hits": {
        "total": {
            "value": 182,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },

And then I make a aggregation to know how many documents have the source instagagram or twitter and it returns me:

"bySource": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": "instagram",
                    "doc_count": 162
                },
                {
                    "key": "twitter",
                    "doc_count": 20
                }
            ]
        }

Is it possible to get the percentage of documents that have source twitter and instagram? So the percentage of documents that have source instagram is 89 % and twitter 11%.

My aggregation code its like this:


"aggs": {
        "bySource": {
            "terms": {
                "field": "profile.source.keyword"
            }
        }
}

Let me know if this is possible. Thank you

0 Answers
Related