ElasticSearch aggregation function ElasticSearch aggregation function elasticsearch elasticsearch

ElasticSearch aggregation function


You can get get roughly what you want by using sub aggregations available in 1.0. Assuming the documents are structured as author, weekday and status, you could using the aggregation below:

{  "size": 0,  "aggs": {    "author": {      "terms": {        "field": "author"      },      "aggs": {        "days": {          "terms": {            "field": "weekday"          },          "aggs": {            "status": {              "terms": {                "field": "status"              }            }          }        }      }    }  }}

Which gives you the following result:

{   ...   "aggregations": {      "author": {         "buckets": [            {               "key": "me",               "doc_count": 3,               "days": {                  "buckets": [                     {                        "key": "monday",                        "doc_count": 2,                        "status": {                           "buckets": [                              {                                 "key": "bad",                                 "doc_count": 1                              },                              {                                 "key": "ok",                                 "doc_count": 1                              }                           ]                        }                     },                     {                        "key": "tuesday",                        "doc_count": 1,                        "status": {                           "buckets": [                              {                                 "key": "ok",                                 "doc_count": 1                              }                           ]                        }                     }                  ]               }            }         ]      }   }}