createCommand() public method

Creates a DB command that can be used to execute this query.
public createCommand ( Connection $db = null ) : Command
$db Connection the database connection used to execute the query. If this parameter is not given, the `elasticsearch` application component will be used.
return Command the created DB command instance.
Esempio n. 1
0
 /**
  * @inheritdoc
  */
 public function createCommand($db = null)
 {
     $this->mapAggregations();
     $searchQuery = $this->getSearchQuery();
     if ($searchQuery) {
         $this->query = $this->mapQuery($searchQuery);
     }
     return parent::createCommand($db);
 }
 /**
  * @return mixed
  */
 public function Build()
 {
     // Remove all new lines etc. from the json to make it valid
     $this->query = json_decode($this->query);
     $query = new Query();
     $query->fields(['name'])->from('api-builder', 'api')->highlight([])->limit(5)->query($this->query);
     // build and execute the query
     $command = $query->createCommand();
     $rows = $command->search();
     // this way you get the raw output of elasticsearch.
     return $rows;
 }