/**
  * Check if top hits aggregation works when it's nested.
  */
 public function testTopHitsAggregationNested()
 {
     $topAggregation = new TopHitsAggregation('test-top_hits');
     $termAggregation = new TermsAggregation('test_term');
     $termAggregation->setField('description');
     $termAggregation->addAggregation($topAggregation);
     /** @var Repository $repo */
     $repo = $this->getManager()->getRepository('AcmeTestBundle:Product');
     $search = $repo->createSearch()->addAggregation($termAggregation)->addSort(new Sort('_id', Sort::ORDER_ASC));
     $results = $repo->execute($search, Repository::RESULTS_RAW);
     $this->assertTrue(isset($results['aggregations']['agg_test_term']['buckets'][0]['agg_test-top_hits']['hits']));
     $result = $results['aggregations']['agg_test_term']['buckets'][0]['agg_test-top_hits']['hits'];
     $this->assertEquals(2, $result['total']);
     $this->assertTrue(isset($results['aggregations']['agg_test_term']['buckets'][1]['agg_test-top_hits']['hits']));
     $result = $results['aggregations']['agg_test_term']['buckets'][1]['agg_test-top_hits']['hits'];
     $this->assertEquals(1, $result['total']);
 }
 /**
  * Test for terms aggregation with shard_size, collect_mode, shard_min_doc_count.
  */
 public function testTermsAggregationWithCollectMode()
 {
     /** @var Repository $repo */
     $repo = $this->getManager()->getRepository('AcmeTestBundle:Product');
     $aggregationFoo = new TermsAggregation('test_foo');
     $aggregationFoo->setField('title');
     $aggregationFoo->addParameter('size', 5);
     $aggregationFoo->addParameter('shard_size', 5);
     $aggregationFoo->addParameter('execution_hint', 'map');
     $aggregationFoo->addParameter('collect_mode', 'breadth_first');
     $aggregationBar = new TermsAggregation('test_bar');
     $aggregationBar->setField('title');
     $aggregationBar->addParameter('shard_min_doc_count', 5);
     $aggregationFoo->addAggregation($aggregationBar);
     $search = $repo->createSearch()->addAggregation($aggregationFoo);
     $results = $repo->execute($search, Repository::RESULTS_RAW);
     $this->assertEquals(3, count($results['aggregations'][$aggregationFoo->getName()]['buckets']));
 }