toArray() public method

public toArray ( ) : array
return array
Esempio n. 1
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();
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
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;
 }
 /**
  * {@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;
 }
Esempio n. 6
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;
 }