Skip to content

Commit 0b410cd

Browse files
committed
Fix mapping issue for aliases #588
1 parent 9a53f12 commit 0b410cd

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

changes.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGES
44
- Update to elasticsearch 1.1.1 http://www.elasticsearch.org/downloads/1-1-1/
55
- Remove CustomFiltersScore and CustomScore query as removed in elasticsearch 1.1.0 https://github.com/elasticsearch/elasticsearch/pull/5076/files
66
- Update Node Info to use plugins instead of plugin (https://github.com/elasticsearch/elasticsearch/pull/5072)
7+
- Fix mapping issue for aliases #588
78

89
2014-04-17
910
- Only trap real JSON parse errors in Response class #586

lib/Elastica/Index.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,12 @@ public function getMapping()
9494

9595
$response = $this->request($path, Request::GET);
9696
$data = $response->getData();
97-
if (isset($data[$this->getName()]['mappings'])) {
98-
return $data[$this->getName()]['mappings'];
97+
98+
// Get first entry as if index is an Alias, the name of the mapping is the real name and not alias name
99+
$mapping = array_shift($data);
100+
101+
if (isset($mapping['mappings'])) {
102+
return $mapping['mappings'];
99103
}
100104

101105
return array();

test/lib/Elastica/Test/TypeTest.php

+31
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,37 @@ public function testExists()
771771
$index->delete();
772772
$this->assertFalse($index->exists());
773773
}
774+
775+
public function testGetMappingAlias() {
776+
777+
$indexName = 'test-mapping';
778+
$aliasName = 'test-mapping-alias';
779+
780+
$index = $this->_createIndex($indexName);
781+
$indexName = $index->getName();
782+
$index->addAlias($aliasName);
783+
784+
$type = new Type($index, 'test');
785+
$mapping = new Mapping($type, array(
786+
'id' => array('type' => 'integer', 'store' => 'yes'),
787+
));
788+
$type->setMapping($mapping);
789+
790+
$client = $index->getClient();
791+
792+
// Index mapping
793+
$mapping1 = $client->getIndex($indexName)->getMapping();
794+
795+
// Alias mapping
796+
$mapping2 = $client->getIndex($aliasName)->getMapping();
797+
798+
// Make sure, a mapping is set
799+
$this->assertNotEmpty($mapping1);
800+
801+
// Alias and index mapping should be identical
802+
$this->assertEquals($mapping1, $mapping2);
803+
804+
}
774805
}
775806

776807
class SerializerMock

0 commit comments

Comments
 (0)