I am trying to Sum up Data through a Child Aggregation in Elasticsearch 2.1.
With Pipelining i am trying to get the Child Aggregation Data summed up on the Parent Level of the Aggregation:
{
"query": {
"match_all": {}
},
"aggs": {
"unit": {
"terms": {
"size": 500,
"field": "unit_id"
},
"aggs": {
"total_active_ministers_by_unit": {
"sum_bucket": {
"buckets_path": "ministers>active_minister_by_ministry.value"
}
},
"ministers": {
"children": {
"type": "member_ministry"
},
"aggs": {
"active_minister_by_ministry": {
"sum_bucket": {
"buckets_path": "ministry>active_minister._count"
}
},
"ministry": {
"terms": {
"field": "member_version",
"size": 1,
"order": {
"_term": "desc"
}
},
"aggs": {
"active_minister": {
"filter": {
"range": {
"ministry_date_start": {
"lte": "now/d",
"gte": "now-96M/M"
}
}
}
},
"ministry_type": {
"terms": {
"field": "ministry"
}
}
}
}
}
}
}
}
}
}
After firing the Query i get the Following Answer from the Rest API:
{
"error": {
"root_cause": [
],
"type": "reduce_search_phase_exception",
"reason": "[reduce] ",
"phase": "fetch",
"grouped": true,
"failed_shards": [
],
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Cannot find an aggregation named [value] in [active_minister]"
}
},
"status": 503
}
The Elasticsearch Server Console gives me the Following:
[2015-12-03 12:19:57,974][INFO ][rest.suppressed ] /unit_member/unit/_search Params: {index=unit_member, type=unit}
Failed to execute phase [fetch], [reduce]
at org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction$2.onFailure(TransportSearchQueryThenFetchAction.java:162)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: Cannot find an aggregation named [value] in [active_minister]
at org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregation.getProperty(InternalSingleBucketAggregation.java:111)
at org.elasticsearch.search.aggregations.InternalMultiBucketAggregation$InternalBucket.getProperty(InternalMultiBucketAggregation.java:98)
at org.elasticsearch.search.aggregations.pipeline.BucketHelpers.resolveBucketValue(BucketHelpers.java:160)
at org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregator.doReduce(BucketMetricsPipelineAggregator.java:74)
at org.elasticsearch.search.aggregations.pipeline.SiblingPipelineAggregator.reduce(SiblingPipelineAggregator.java:68)
at org.elasticsearch.search.aggregations.InternalAggregation.reduce(InternalAggregation.java:155)
at org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:170)
at org.elasticsearch.search.aggregations.bucket.terms.InternalTerms$Bucket.reduce(InternalTerms.java:110)
at org.elasticsearch.search.aggregations.bucket.terms.InternalTerms.doReduce(InternalTerms.java:220)
at org.elasticsearch.search.aggregations.InternalAggregation.reduce(InternalAggregation.java:153)
at org.elasticsearch.search.aggregations.InternalAggregations.reduce(InternalAggregations.java:170)
at org.elasticsearch.search.controller.SearchPhaseController.merge(SearchPhaseController.java:409)
at org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction$2.doRun(TransportSearchQueryThenFetchAction.java:149)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
... 3 more
Is this a bug which should be reported? Or am i handling the Pipelining the wrong way?
Here is my mapping:
"member_ministry": {
"dynamic": "false",
"_routing": {
"required": true
},
"properties": {
"date_ended": {
"ignore_malformed": true,
"format": "yyyy-MM-dd",
"type": "date"
},
"birthday": {
"ignore_malformed": true,
"format": "yyyy-MM-dd",
"type": "date"
},
"parent_path": {
"index": "not_analyzed",
"type": "string"
},
"forename": {
"type": "string"
},
"ministry": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"lastname": {
"type": "string"
},
"unit_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"ministry_date_start": {
"ignore_malformed": true,
"format": "yyyy-MM-dd",
"type": "date"
},
"date_created": {
"ignore_malformed": true,
"format": "yyyy-MM-dd",
"type": "date"
},
"ministry_date_end": {
"ignore_malformed": true,
"format": "yyyy-MM-dd",
"type": "date"
},
"sealing_date": {
"ignore_malformed": true,
"format": "yyyy-MM-dd",
"type": "date"
},
"ministry_unit_ids": {
"index": "not_analyzed",
"type": "string"
},
"member_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"version_state": {
"index": "not_analyzed",
"type": "string"
},
"member_ministry_id": {
"index": "not_analyzed",
"type": "string"
},
"gender": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"member_version": {
"store": true,
"type": "integer"
},
"client_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"primary_ministry_id": {
"index": "not_analyzed",
"type": "string"
}
},
"_parent": {
"type": "unit"
}
},
"unit": {
"dynamic": "false",
"properties": {
"versions": {
"properties": {
"apostle_district_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"date_ended": {
"ignore_malformed": true,
"format": "yyyy-MM-dd",
"type": "date"
},
"unit_type_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"parent_path": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"sub_district_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"district_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"unit_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"date_created": {
"ignore_malformed": true,
"format": "yyyy-MM-dd",
"type": "date"
},
"bishop_district_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"administration_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"date_opened": {
"ignore_malformed": true,
"format": "yyyy-MM-dd",
"type": "date"
},
"district_church_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"district_apostle_helper_area_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"international_church_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"unit_type": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"district_apostle_area_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"unit_version": {
"store": true,
"type": "integer"
},
"client_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"regional_administration_center_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
}
}
},
"unit_id": {
"index": "not_analyzed",
"store": true,
"type": "string"
}
}
Here is a minimal Set of Data from the Index
Unit
http://pastie.org/private/wippg2zfdrsiul5iaqiga
MemberMinistry:
I'm guessing that this is a bug.
When I took this part out:
I got these results:
But trying to pipeline across the parent/child relationship causes an error.
This probably ought to be reported as a bug, unless I'm missing something.
Here is the code I used to test it out:
http://sense.qbox.io/gist/075732dfe51916538ff13ea76a2cec1f7532c691