public function testGetDocsInType() { $typeName = 'type-name'; $value = 22; $type = $this->getMockBuilder('\\Elastification\\BackupRestore\\Entity\\IndexTypeStats\\Type')->disableOriginalConstructor()->getMock(); $type->expects($this->once())->method('getName')->willReturn($typeName); $type->expects($this->once())->method('getDocsInType')->willReturn($value); $this->index->addType($type); $this->assertSame($value, $this->index->getDocsInType($typeName)); }
/** * 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; }