Alternative 1:
GET /test_sum_bucket_agg/_search
{
"size":0,
"aggs":{
"f":{
"filters": {
"filters": {
"all": {"match_all":{}}
}
},
"aggs":{
"sename":{
"terms":{
"field":"currentApplicantInfo.seName"
}
},
"STUB":{
"bucket_script": {
"buckets_path": {
"countA": "sename['ALLOGENE THERAPEUTICS']>_count",
"countC": "sename['CELLECTIS']>_count"
},
"script": "params.countA + params.countC",
"format": "#"
}
}
}
}
}
}
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"f" : {
"buckets" : {
"all" : {
"doc_count" : 3,
"sename" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "ALLOGENE THERAPEUTICS",
"doc_count" : 3
},
{
"key" : "CELLECTIS",
"doc_count" : 1
},
{
"key" : "PFIZER",
"doc_count" : 1
}
]
},
"STUB" : {
"value" : 4.0,
"value_as_string" : "4"
}
}
}
}
}
}
Alternative 2:
GET /test_sum_bucket_agg/_search
{
"runtime_mappings": {
"countAC": {
"type": "long",
"script":{
"lang": "painless",
"source": "int x=0; for (sename in doc['currentApplicantInfo.seName']){if ((sename == 'ALLOGENE THERAPEUTICS') || (sename == 'CELLECTIS')){x = x+1}} emit(x)"
}
}
},
"size":0,
"fields": [
{"field": "countAC"}
],
"aggs":{
"STUB":{
"sum":{
"field": "countAC",
"format": "#"
}
},
"terms":{
"terms":{
"field":"currentApplicantInfo.seName"
}
}
}
}
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"terms" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "ALLOGENE THERAPEUTICS",
"doc_count" : 3
},
{
"key" : "CELLECTIS",
"doc_count" : 1
},
{
"key" : "PFIZER",
"doc_count" : 1
}
]
},
"STUB" : {
"value" : 4.0,
"value_as_string" : "4"
}
}
}
I also recommend to do it on the client side as he said on another topic.