Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use doc_count in an aggregations range query in ElasticSearch 1.0

I have a bunch of user generated events in my ES cluster. Each event contains the user's UUID.

I'm trying to write a query that buckets users into low, medium and high activity based on the number of events each user generates.

I'm using this query to get the number of events generated by each user:

{
    "aggs" : {
        "users" : { 
            "terms" : { "field" : "user_id.raw" }
         }
    }
}

This works fine, but I need to further bucket the results into a range query using the previous results "doc_count", so that I can sort each user into a low, med, high activity bucket.

I tried a bunch of ways to access the doc_count field using a sub-aggregation but never manage to get it work. I figured this would be a fairly common use case, but can't seem to crack it, so any help would be much appreciated.

like image 358
whisperstream Avatar asked Feb 26 '14 01:02

whisperstream


People also ask

What is Doc_count?

_doc_count fieldedit Bucket aggregations always return a field named doc_count showing the number of documents that were aggregated and partitioned in each bucket. Computation of the value of doc_count is very simple. doc_count is incremented by 1 for every document collected in each bucket.

What is sub aggregation in Elasticsearch?

The sub-aggregations will be computed for the buckets which their parent aggregation generates. There is no hard limit on the level/depth of nested aggregations (one can nest an aggregation under a "parent" aggregation, which is itself a sub-aggregation of another higher-level aggregation).

What is terms aggregation in Kibana?

What is Kibana Aggregation? Aggregation refers to the collection of documents or a set of documents obtained from a particular search query or filter. Aggregation forms the main concept to build the desired visualization in Kibana.


1 Answers

I have updated https://github.com/elasticsearch/elasticsearch/issues/4983?_pjax=%23js-repo-pjax-container with this issue as well.

Looks like a minor enhancement to the aggregation framework (but) will be really useful.

like image 93
Am1 Avatar answered Oct 05 '22 05:10

Am1