/** * Updates elasticsearch client mapping. * * @param array $types Specific types to update. * * @return int */ public function updateTypes(array $types = []) { $this->isReadOnly('Update types'); if (!$this->getMapping($types)) { return -1; } $tempSettings = $this->settings; $tempSettings['index'] = uniqid('mapping_check_'); $mappingCheckConnection = new Connection($this->getClient(), $tempSettings); $mappingCheckConnection->createIndex(); $mappingCheckConnection->createTypes($types); $newMapping = $mappingCheckConnection->getMappingFromIndex($types); $oldMapping = $this->getMappingFromIndex($types); $mappingCheckConnection->dropIndex(); $tool = new MappingTool(); $updated = (int) $tool->checkMapping($oldMapping, $newMapping); if ($updated) { $this->unloadMappingArray($tool->getRemovedTypes()); $this->loadMappingArray($tool->getUpdatedTypes()); } return $updated; }