/** * Builds a Mapping collection from the annotation sources that are present * * @throws \Flowpack\ElasticSearch\Exception * @return \Flowpack\ElasticSearch\Mapping\MappingCollection<\Flowpack\ElasticSearch\Domain\Model\Mapping> */ public function buildMappingInformation() { if (!$this->client instanceof Model\Client) { throw new \Flowpack\ElasticSearch\Exception('No client was given for mapping retrieval. Set a client BackendMappingBuilder->setClient().', 1339678111); } $this->indicesWithoutTypeInformation = array(); $response = $this->client->request('GET', '/_mapping'); $mappingInformation = new MappingCollection(MappingCollection::TYPE_BACKEND); $mappingInformation->setClient($this->client); $indexNames = $this->indexInformer->getAllIndexNames(); foreach ($response->getTreatedContent() as $indexName => $indexSettings) { if (!in_array($indexName, $indexNames)) { continue; } $index = new Model\Index($indexName); if (empty($indexSettings)) { $this->indicesWithoutTypeInformation[] = $indexName; } foreach ($indexSettings as $typeName => $typeSettings) { $type = new Model\GenericType($index, $typeName); $mapping = new Model\Mapping($type); if (isset($typeSettings['properties'])) { foreach ($typeSettings['properties'] as $propertyName => $propertySettings) { foreach ($propertySettings as $key => $value) { $mapping->setPropertyByPath(array($propertyName, $key), $value); } } } $mappingInformation->add($mapping); } } return $mappingInformation; }
/** * Refresh an index in ElasticSearch * * @param string $indexName The name of the index to be removed * @param string $clientName The client name to use */ public function refreshCommand($indexName, $clientName = null) { if (!in_array($indexName, $this->indexInformer->getAllIndexNames())) { $this->outputFormatted("The index <b>%s</b> is not configured in the current application", array($indexName)); } $client = $this->clientFactory->create($clientName); try { $index = new Index($indexName, $client); if (!$index->exists()) { $this->outputFormatted("The index <b>%s</b> does not exists", array($indexName)); $this->quit(1); } $index->refresh(); $this->outputFormatted("Index <b>%s</b> refreshed with success", array($indexName)); } catch (Exception $exception) { $this->outputFormatted("Unable to refresh an index named: <b>%s</b>", array($indexName)); $this->quit(1); } }