Add in meta.aggregations field
489012
function createBuckets(terms) {
            return _.map(terms, (term) => {
              // 1. see if there are other terms & if they have buckets.
              const retVal = { key: term.key, count: term.doc_count };

              _.each(term, (aggResponse, responseKey) => {
                if (responseKey === 'key' || responseKey === 'doc_count') {
                  return null;
                } else if (aggResponse.buckets) {
                  retVal[responseKey] = createBuckets(aggResponse.buckets);
                } else if (aggResponse.hits && aggResponse.hits.hits) {
                  // top_hits aggs result from nested query w/o reverse nesting.
                  retVal[responseKey] = getTopHitsResult(aggResponse, responseKey, _esResponse, aggregationObjects);
                  // to combine nested aggs w others, you have to un-nest them, & this takes up an aggregation-space.
                } else if (responseKey !== 'reverse_nesting' && aggResponse) { // stats & extended_stats aggs
                  // This means it's the result of a nested stats or extended stats query.
                  if (aggResponse[responseKey]) {
                    retVal[responseKey] = aggResponse[responseKey];
                  } else {
                    retVal[responseKey] = aggResponse;
                  }
                } else if (responseKey === 'reverse_nesting') {
                  _.each(aggResponse, (reverseNestedResponseProperty, reverseNestedResponseKey) => {
                    if (reverseNestedResponseKey === 'doc_count') {
                      return null;
                    } else if (reverseNestedResponseProperty.buckets) {
                      retVal[reverseNestedResponseKey] = createBuckets(reverseNestedResponseProperty.buckets);
                      // this gets a little complicated because reverse-nested then renested subdocuments are ..
                      // complicated (because the extra aggs for nesting throws things off).
                    } else if (reverseNestedResponseProperty[reverseNestedResponseKey] &&
                        reverseNestedResponseProperty[reverseNestedResponseKey].buckets) {
                      retVal[reverseNestedResponseKey] = createBuckets(
                        reverseNestedResponseProperty[reverseNestedResponseKey].buckets);

                      // this gets a little MORE complicated because of reverse-nested then renested top_hits aggs
                    } else if (reverseNestedResponseProperty.hits && reverseNestedResponseProperty.hits.hits) {
                      retVal[reverseNestedResponseKey] = getTopHitsResult(reverseNestedResponseProperty,
                        reverseNestedResponseKey, _esResponse, aggregationObjects);

                      // stats & extended_stats aggs
                    } else if (reverseNestedResponseProperty) {
                      // This means it's the result of a nested stats or extended stats query.
                      if (reverseNestedResponseProperty[reverseNestedResponseKey]) {
                        retVal[reverseNestedResponseKey] = reverseNestedResponseProperty[reverseNestedResponseKey];
                      } else {
                        retVal[reverseNestedResponseKey] = reverseNestedResponseProperty;
                      }
                    }
                    return null;
                  });
                }
                return null;
              });

              return retVal;
            });
          }
53667
def add_association(name, type, metadata={})
      associations << (metadata || {}).merge(:name => name.to_sym, :type => type.to_sym)
    end
1071459
final public function addAggregateColumn(Aggregate $aggregate)
    {
        $parts = explode(".", $aggregate->getAggregateColumnName());

        if (count($parts) > 1) {
            $columnName = $parts[count($parts) - 1];

            $relationships = array_slice($parts, 0, count($parts) - 1);

            $aggregate->setAliasDerivedColumn(str_replace(".", "", $aggregate->getAggregateColumnName()));
            $aggregate->setAggregateColumnName($columnName);

            $collection = $this->createIntersectionForRelationships($relationships, [$aggregate->getAlias()]);
            $collection->addAggregateColumn($aggregate);
            return $this;
        }

        $this->aggregateColumns[$aggregate->getAlias()] = $aggregate;
        $this->invalidate();

        return $this;
    }
1021117
private BasicDBObject createAggregation(EntityMetadata metadata)
    {
        if (kunderaQuery.getSelectStatement() != null)
        {
            Metamodel metaModel = kunderaMetadata.getApplicationMetadata().getMetamodel(metadata.getPersistenceUnit());
            EntityType entityType = metaModel.entity(metadata.getEntityClazz());
            AbstractManagedType managedType = (AbstractManagedType) metaModel.entity(metadata.getEntityClazz());
            boolean hasLob = managedType.hasLobAttribute();

            BasicDBObject aggregation = new BasicDBObject();

            SelectClause selectClause = (SelectClause) kunderaQuery.getSelectStatement().getSelectClause();
            Expression expression = selectClause.getSelectExpression();

            buildAggregation(aggregation, expression, metadata, entityType, hasLob);

            if (aggregation.size() == 0)
            {
                return null;
            }

            if (!aggregation.containsField("_id"))
            {
                aggregation.put("_id", null);
            }

            return aggregation;
        }

        return null;
    }
287593
def _use_aggregation(self, agg, columns=None):
        """"""
        if not columns:
            columns = self._columns
        from pyspark.sql import functions as F
        aggs = map(lambda column: agg(column).alias(column), self._columns)
        aggRdd = self._grouped_spark_sql.agg(*aggs)
        df = DataFrame.from_schema_rdd(aggRdd, self._by)
        return df
2248
private function addColumn($field, $type = "migration", $meta = "")
    {


        if ($type == 'migration') {

            $syntax = sprintf("\$table->%s('%s')", $field['type'], $field['name']);

            // If there are arguments for the schema type, like decimal('amount', 5, 2)
            // then we have to remember to work those in.
            if ($field['arguments']) {
                $syntax = substr($syntax, 0, -1) . ', ';

                $syntax .= implode(', ', $field['arguments']) . ')';
            }

            foreach ($field['options'] as $method => $value) {
                $syntax .= sprintf("->%s(%s)", $method, $value === true ? '' : $value);
            }

            $syntax .= ';';


        } elseif ($type == 'view-index-header') {

            // Fields to index view
            $syntax = sprintf("<th>%s", strtoupper($field['name']));
            $syntax .= '</th>';

        } elseif ($type == 'view-index-content') {

            // Fields to index view
            $syntax = sprintf("<td>{{\$%s->%s", $meta['var_name'], strtolower($field['name']));
            $syntax .= '}}</td>';

        } elseif ($type == 'view-show-content') {

            // Fields to show view
            $syntax = sprintf("<div class=\"form-group\">\n" .
                str_repeat(' ', 21) . "<label for=\"%s\">%s</label>\n" .
                str_repeat(' ', 21) . "<p class=\"form-control-static\">{{\$%s->%s}}</p>\n" .
                str_repeat(' ', 16) . "</div>", strtolower($field['name']), strtoupper($field['name']), $meta['var_name'], strtolower($field['name']));


        } elseif ($type == 'view-edit-content') {
            $syntax = $this->buildField($field, $type, $meta['var_name']);
        } elseif ($type == 'view-create-content') {
            $syntax = $this->buildField($field, $type, $meta['var_name'], false);
        } else {
            // Fields to controller
            $syntax = sprintf("\$%s->%s = \$request->input(\"%s", $meta['var_name'], $field['name'], $field['name']);
            $syntax .= '");';
        }


        return $syntax;
    }
1097884
function addDoc(array = [], action) {
  const { meta, payload } = action;
  if (!meta.subcollections || meta.storeAs) {
    return [
      ...array.slice(0, payload.ordered.newIndex),
      { id: meta.doc, ...payload.data },
      ...array.slice(payload.ordered.newIndex),
    ];
  }

  // Add doc to subcollection by modifying the existing doc at this level
  return modifyDoc(array, action);
}
722159
function addMetadataValues(line, sub) {
  _.each(metaDataHeaders, function(headerName) {
    if (headerName === 'submissionCompletedTimestamp' || headerName ===
      'updatedTimestamp' || sub[headerName] === undefined) {
      line += sub[headerName] + ',';
    } else {
      var parsedLine = csvStr(sub[headerName]);
      line += parsedLine + ',';
    }

  });
  return line;
}
186454
def _add_field_column(self, field):  # pragma: no cover
        """"""
        @self.add_column(name=field)
        def get_my_label(cluster_id):
            return self.cluster_meta.get(field, cluster_id)
272407
def add_aggregator(agg)
      agg = RequestLogAnalyzer::Aggregator.const_get(RequestLogAnalyzer.to_camelcase(agg)) if agg.is_a?(String) || agg.is_a?(Symbol)
      @aggregators << agg.new(@source, @options)
    end
930807
private function aggregation($field, $isMulti = false, $useMaster = false, $operation = 'COUNT')
    {
        is_string($isMulti) && $this->groupBy($isMulti)->columns($isMulti);
        $count = $this->columns(["{$operation}({$field})" => '__res__'])->select(null, null, $useMaster);
        if ($isMulti) {
            $return = [];
            foreach ($count as $val) {
                $return[$val[$isMulti]] = $operation === 'COUNT' ? intval($val['__res__']) : floatval($val['__res__']);
            }
            return $return;
        } else {
            return $operation === 'COUNT' ? intval($count[0]['__res__']) : floatval($count[0]['__res__']);
        }
    }
154780
def before_add_field(self, field):
        
        if self.extract_fields and field.name == '*':
            field.ignore = True
            fields = [model_field.column for model_field in self.model._meta.fields]
            self.add_fields(fields)
576238
private function addAggregationFilters()
    {
        foreach ($this->_data as $requestName => $requestConfig) {
            if (isset($requestConfig['aggregations'])) {
                $aggregations = [];

                foreach ($requestConfig['aggregations'] as $aggName => $aggConfig) {
                    $aggregations[$aggName] = $this->replaceAggregationFilter($aggConfig);
                }

                $this->_data[$requestName]['aggregations'] = $aggregations;
            }
        }
    }
323396
private AbstractAggregationBuilder makeTopHitsAgg(MethodField field) {
        String alias = gettAggNameFromParamsOrAlias(field);
        TopHitsAggregationBuilder topHits = AggregationBuilders.topHits(alias);
        List<KVValue> params = field.getParams();
        String[] include = null;
        String[] exclude = null;
        for (KVValue kv : params) {
            switch (kv.key) {
                case "from":
                    topHits.from((int) kv.value);
                    break;
                case "size":
                    topHits.size((int) kv.value);
                    break;
                case "include":
                    include = kv.value.toString().split(",");
                    break;
                case "exclude":
                    exclude = kv.value.toString().split(",");
                    break;
                case "alias":
                case "nested":
                case "reverse_nested":
                case "children":
                    break;
                default:
                    topHits.sort(kv.key, SortOrder.valueOf(kv.value.toString().toUpperCase()));
                    break;
            }
        }
        if (include != null || exclude != null) {
            topHits.fetchSource(include, exclude);
        }
        return topHits;
    }
740628
protected void addEntityFieldsToDocument(EntityMetadata metadata, Object entity, Document document,
        MetamodelImpl metaModel) {
        String indexName = metadata.getIndexName();
        Map<String, PropertyIndex> indexProperties = metadata.getIndexProperties();
        for (String columnName : indexProperties.keySet()) {
            PropertyIndex index = indexProperties.get(columnName);
            java.lang.reflect.Field property = index.getProperty();
            String propertyName = index.getName();
            addFieldToDocument(entity, document, property, propertyName, indexName);
        }

        if (metaModel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType())) {
            Object id = PropertyAccessorHelper.getId(entity, metadata);
            EmbeddableType embeddableId = metaModel.embeddable(metadata.getIdAttribute().getBindableJavaType());
            Set<Attribute> embeddedAttributes = embeddableId.getAttributes();
            indexCompositeKey(embeddedAttributes, metadata, id, document, metaModel);
        }
    }
990703
def add_fields(self, field_dict):
    
    for key, field in field_dict.items():
      self.add_field(key, field)
96978
def find_field_meta(obj, value):
    
    if "__" in value:
        value_list = value.split("__")
        child_obj = obj._meta.get_field(value_list[0]).rel.to
        return find_field_meta(child_obj, "__".join(value_list[1:]))
    return obj._meta.get_field(value)