/**
  * Returns a query setup for getting the 'type' aggregation
  *
  * @param Cake\ElasticSearch\Query $query The Query Object
  * @return Cake\ElasticSearch\Query
  */
 public function findTypes($query)
 {
     $facet = new TermsAggregation('type');
     $facet->setField('_type');
     $facet->setSize(200);
     $query->aggregate($facet);
     return $query->limit(1);
 }
 /**
  * Alters the query object to add the time constraints as they can be found in
  * the request object.
  *
  * @param Cake\Network\Request $request The request where query string params can be found
  * @param Cake\ElasticSearch\Query $query The Query to add filters to
  * @return void
  */
 protected function addTimeConstraints($request, $query)
 {
     if ($request->query('from')) {
         $from = new \DateTime($request->query('from'));
         $until = new \DateTime();
     }
     if ($request->query('until')) {
         $until = new \DateTime($request->query('until'));
     }
     if (!empty($from)) {
         $query->where(function ($builder) use($from, $until) {
             return $builder->between('@timestamp', $from->format('Y-m-d H:i:s'), $until->format('Y-m-d H:i:s'));
         });
         return;
     }
     if (!empty($until)) {
         $query->where(['@timestamp <=' => $until->format('Y-m-d H:i:s')]);
     }
 }