I'm trying to group term aggregations.
My _search payload:
{
"size": 25,
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "*"
}
},
{
"terms": {
"activityId": [1,2]
}
}
]
}
},
"aggregations": {
"site_filter": {
"terms": {
"field": "definition.indexGroups.indexGroup.groupId"
},
"aggregations": {
"site_keyword": {
"terms": {
"field": "definition.indexGroups.indexGroup.index.keyword"
}
}
}
}
}
}
Actual Response:
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 2.0,
"hits" : [
{
"_index" : "activity_2",
"_type" : "activity",
"_id" : "record_1",
"_score" : 2.0,
"_source" : {
"definition" : {
"indexGroups" : {
"indexGroup" : [
{
"index" : [
{
"code" : "Diabetes - General",
"keyword" : "Diabetes - General"
},
{
"code" : "Family Medicine",
"keyword" : "Family Medicine"
}
],
"groupId" : "Topics Group"
},
{
"index" : [
{
"code" : "Kidney Disease",
"keyword" : "Kidney Disease"
}
],
"groupId" : "General Group"
}
]
},
},
"activityId" : "1",
"activityGuid" : "record_1"
}
},
{
"_index" : "activity_2",
"_type" : "activity",
"_id" : "record_2",
"_score" : 2.0,
"_source" : {
"definition" : {
"indexGroups" : {
"indexGroup" : [
{
"index" : [
{
"code" : "Diabetes - General",
"keyword" : "Diabetes - General"
}
],
"groupId" : "Topics Group"
}
]
},
},
"activityId" : "2",
"activityGuid" : "record_2"
}
}
]
},
"aggregations" : {
"site_filter" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "Topics Group",
"doc_count" : 2,
"site_keyword" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "Diabetes - General",
"doc_count" : 2
},
{
"key" : "Family Medicine",
"doc_count" : 1
},
{
"key" : "Kidney Disease",
"doc_count" : 1
}
]
}
},
{
"key" : "General Group",
"doc_count" : 1,
"site_keyword" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "Diabetes - General",
"doc_count" : 1
},
{
"key" : "Family Medicine",
"doc_count" : 1
},
{
"key" : "Kidney Disease",
"doc_count" : 1
}
]
}
}
]
}
}
}
I expected and wanted the aggregations result to be as follows:
Topics Group:
Diabetes - General (2)
Family Medicine (1)
General Group:
Kidney Disease (1)
However the sub aggregate topics are the same for both top aggregates.