/** * Tests building the elasticsearch query body. */ public function testBuildBody() { $this->specify('match all query body page 1', function () { $this->search->setPage(1); $this->search->setSize(100); verify($this->search->buildBody())->equals(['query' => ['match_all' => []], 'size' => 100, 'from' => 0]); }); $this->specify('match all query body page 2', function () { $this->search->setPage(2); $this->search->setSize(100); verify($this->search->buildBody())->equals(['query' => ['match_all' => []], 'size' => 100, 'from' => 100]); }); $this->specify('bool query body page 1', function () { $this->search->setPage(1); $this->search->setSize(100); $this->search->setQuery($this->query); verify($this->search->buildBody())->equals(['query' => ['bool' => ['must' => [['term' => ['field1' => 'value1']]]]], 'size' => 100, 'from' => 0]); }); $this->specify('match all query with sort body', function () { $this->search->setSort($this->sort); verify($this->search->buildBody())->equals(['query' => ['match_all' => []], 'sort' => ['_score'], 'size' => 100, 'from' => 0]); }); $this->specify('match all query with global aggregation', function () { $this->search->addAggregation($this->aggregation); verify($this->search->buildBody())->equals(['query' => ['match_all' => []], 'aggs' => ['global_name' => ['global' => new stdClass(), 'aggs' => ['min_name' => ['min' => ['field' => 'field_name']], 'max_name' => ['max' => ['field' => 'field_name']]]]], 'size' => 100, 'from' => 0]); }); }
/** * @inheritdoc */ public function execute(Search $search) { return $this->search(['index' => $search->getIndex(), 'type' => $search->getType(), 'body' => $search->buildBody()]); }