code: def _aggregations(search, definitions):
      
      if definitions:
          for name, agg in definitions.items():
              search.aggs[name] = agg if not callable(agg) else agg()
      return search
docs: Add aggregations to query.