code: def should_aggregate(self, req):
          
          try:
              return self.app.config.get('ELASTICSEARCH_AUTO_AGGREGATIONS') or \
                     bool(req.args and int(req.args.get('aggregations')))
          except (AttributeError, TypeError):
              return False
docs: Check the environment variable and the given argument parameter to decide if aggregations needed.
  
          argument value is expected to be '0' or '1'