public function testDocCountWithIndexAndType()
 {
     $count = 11;
     $this->index->expects($this->once())->method('getName')->willReturn(self::INDEX);
     $this->index->expects($this->never())->method('getDocsInIndex');
     $this->index->expects($this->once())->method('getDocsInType')->with(self::TYPE)->willReturn($count);
     $this->stats->addIndex($this->index);
     $result = $this->stats->getDocCount(self::INDEX, self::TYPE);
     $this->assertSame($count, $result);
 }
 /**
  * Checks for number documents in all indices/types
  *
  * @param string $host
  * @param int $port
  * @param int $numberOfIndices
  * @return IndexTypeStats
  * @throws \Exception
  * @author Daniel Wendlandt
  */
 public function getDocCountByIndexType($host, $port = 9200, $numberOfIndices = 10000)
 {
     $this->checkServerInfo($host, $port);
     $queryClassName = $this->getQueryClass('DocsInIndexTypeQuery');
     /** @var QueryInterface $query */
     $query = new $queryClassName();
     /** @var SearchRequest $request */
     $request = $this->requestFactory->create('SearchRequest', $this->serverInfo->version, null, null, $this->getSerializer());
     $request->setBody($query->getBody(array('size' => $numberOfIndices)));
     $client = $this->getClient($host, $port);
     $response = $client->send($request);
     $indexTypeStats = new IndexTypeStats();
     foreach ($response->getData()['aggregations']['count_docs_in_index']['buckets'] as $indexBucket) {
         $index = new IndexTypeStats\Index();
         $index->setName($indexBucket['key']);
         $index->setDocsInIndex($indexBucket['doc_count']);
         foreach ($indexBucket['count_docs_in_types']['buckets'] as $typeBucket) {
             $type = new IndexTypeStats\Type();
             $type->setName($typeBucket['key']);
             $type->setDocsInType($typeBucket['doc_count']);
             $index->addType($type);
         }
         $indexTypeStats->addIndex($index);
     }
     return $indexTypeStats;
 }