/** * Tests getMappingFromIndex method when returns empty array. */ public function testGetMappingFromIndex() { $indices = $this->getMockBuilder('Elasticsearch\\Namespaces\\IndicesNamespace')->disableOriginalConstructor()->getMock(); $indices->expects($this->once())->method('getMapping')->with(['index' => 'foo'])->will($this->returnValue(['baz' => []])); $client = $this->getMockBuilder('Elasticsearch\\Client')->disableOriginalConstructor()->getMock(); $client->expects($this->any())->method('indices')->will($this->returnValue($indices)); $connection = new Connection($client, ['index' => 'foo']); $this->assertEmpty($connection->getMappingFromIndex()); }
/** * 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; }