Inheritance: extends Elastica\Param
 /**
  * Add a sub-aggregation
  * @throws \Elastica\Exception\InvalidException
  *
  * @param  AbstractAggregation $aggregation
  * @return $this
  */
 public function addAggregation(AbstractAggregation $aggregation)
 {
     if ($aggregation instanceof GlobalAggregation) {
         throw new InvalidException('Global aggregators can only be placed as top level aggregators');
     }
     $this->_aggs[$aggregation->getName()] = $aggregation->toArray();
     return $this;
 }
Beispiel #2
0
 /**
  * @param string         $name
  * @param AbstractFilter $filter
  */
 public function __construct($name, AbstractFilter $filter = null)
 {
     parent::__construct($name);
     if ($filter !== null) {
         $this->setFilter($filter);
     }
 }
Beispiel #3
0
 /**
  * @throws InvalidException If buckets path is not set
  *
  * @return array
  */
 public function toArray()
 {
     if (!$this->hasParam('buckets_path')) {
         throw new InvalidException('Buckets path is required');
     }
     return parent::toArray();
 }
Beispiel #4
0
 /**
  * @return array
  */
 public function toArray()
 {
     $array = parent::toArray();
     // if there are no params, it's ok, but ES will throw exception if json
     // will be like {"top_hits":[]} instead of {"top_hits":{}}
     if (empty($array['top_hits'])) {
         $array['top_hits'] = new \stdClass();
     }
     return $array;
 }
 /**
  * {@inheritdoc}
  */
 public function toArray()
 {
     $array = parent::toArray();
     $baseName = $this->_getBaseName();
     if (isset($array[$baseName]['script']) && is_array($array[$baseName]['script'])) {
         $script = $array[$baseName]['script'];
         unset($array[$baseName]['script']);
         $array[$baseName] = array_merge($array[$baseName], $script);
     }
     return $array;
 }
 /**
  * @param string        $name
  * @param AbstractQuery $filter
  */
 public function __construct($name, $filter = null)
 {
     parent::__construct($name);
     if ($filter !== null) {
         if ($filter instanceof AbstractFilter) {
             trigger_error('Deprecated: Elastica\\Aggregation\\Filter passing filter as AbstractFilter is deprecated. Pass instance of AbstractQuery instead.', E_USER_DEPRECATED);
         } elseif (!$filter instanceof AbstractQuery) {
             throw new InvalidException('Filter must be instance of AbstractQuery');
         }
         $this->setFilter($filter);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function toArray()
 {
     if (!$this->hasParam('field') && !$this->hasParam('script')) {
         throw new InvalidException('Either the field param or the script param should be set');
     }
     $array = parent::toArray();
     $baseName = $this->_getBaseName();
     if (isset($array[$baseName]['script']) && is_array($array[$baseName]['script'])) {
         $script = $array[$baseName]['script'];
         unset($array[$baseName]['script']);
         $array[$baseName] = array_merge($array[$baseName], $script);
     }
     return $array;
 }
Beispiel #8
0
 /**
  * @param string       $name   the name if this aggregation
  * @param string       $field  the field on which to perform this aggregation
  * @param string|array $origin the point from which distances will be calculated
  */
 public function __construct($name, $field, $origin)
 {
     parent::__construct($name);
     $this->setField($field)->setOrigin($origin);
 }
Beispiel #9
0
 /**
  * @param string $name  the name of this aggregation
  * @param string $field the field on which to perform this aggregation
  */
 public function __construct($name, $field)
 {
     parent::__construct($name);
     $this->setField($field);
 }
Beispiel #10
0
 /**
  * Adds an Aggregation to the query
  *
  * @param AbstractAggregation $agg
  * @return \Elastica\Query Query object
  */
 public function addAggregation(AbstractAggregation $agg)
 {
     if (!array_key_exists('aggs', $this->_params)) {
         $this->_params['aggs'] = array();
     }
     $this->_params['aggs'][$agg->getName()] = $agg->toArray();
     return $this;
 }