How to iterate through a nested object in a scripted metric aggregation

"aggs": {
      "BV_result": {
         "scripted_metric": {
            "init_script": "_agg['BV'] = []",
            "map_script": "_agg.BV.add([_source.memSites,_source.clientId])",
            "combine_script": "result =[:]; for (element in _agg.BV) { client=element[0][0]; if(client.bankName == \"Chase (US)\"){result[element[1]]=[:]; result[element[1]]['status']=client.status;result[element[1]]['createdOn']=client.createdOn;result[element[1]]['bankName']=client.bankName;result[element[1]]['siteId']=client.siteId;result[element[1]]['isVerified']=client.isVerified;};};return result",
            "reduce_script": "output = [:]; found=0; for(value in _aggs){output+=value; found+= value.size()};return [found, output]"
         }
      }
   }

I'm having an issue with the above aggregation scripted_metric query. The query works however I want to be able to iterate over a field called _source.memSites which is a nested object. At the moment all it does is look at the first item of the nested object and returns the query results. What I want to do is to iterate over all the values of the nested object and extract out the relevant fields whenever client.bankName == "Chase (US)". Would appreciate any suggestions on how to do this.