Skip to content

Commit

Permalink
Fix mapping issue for aliases #588
Browse files Browse the repository at this point in the history
  • Loading branch information
ruflin committed Apr 19, 2014
1 parent 9a53f12 commit 0b410cd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGES
- Update to elasticsearch 1.1.1 http://www.elasticsearch.org/downloads/1-1-1/
- Remove CustomFiltersScore and CustomScore query as removed in elasticsearch 1.1.0 https://github.com/elasticsearch/elasticsearch/pull/5076/files
- Update Node Info to use plugins instead of plugin (https://github.com/elasticsearch/elasticsearch/pull/5072)
- Fix mapping issue for aliases #588

2014-04-17
- Only trap real JSON parse errors in Response class #586
Expand Down
8 changes: 6 additions & 2 deletions lib/Elastica/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ public function getMapping()

$response = $this->request($path, Request::GET);
$data = $response->getData();
if (isset($data[$this->getName()]['mappings'])) {
return $data[$this->getName()]['mappings'];

// Get first entry as if index is an Alias, the name of the mapping is the real name and not alias name
$mapping = array_shift($data);

if (isset($mapping['mappings'])) {
return $mapping['mappings'];
}

return array();
Expand Down
31 changes: 31 additions & 0 deletions test/lib/Elastica/Test/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,37 @@ public function testExists()
$index->delete();
$this->assertFalse($index->exists());
}

public function testGetMappingAlias() {

$indexName = 'test-mapping';
$aliasName = 'test-mapping-alias';

$index = $this->_createIndex($indexName);
$indexName = $index->getName();
$index->addAlias($aliasName);

$type = new Type($index, 'test');
$mapping = new Mapping($type, array(
'id' => array('type' => 'integer', 'store' => 'yes'),
));
$type->setMapping($mapping);

$client = $index->getClient();

// Index mapping
$mapping1 = $client->getIndex($indexName)->getMapping();

// Alias mapping
$mapping2 = $client->getIndex($aliasName)->getMapping();

// Make sure, a mapping is set
$this->assertNotEmpty($mapping1);

// Alias and index mapping should be identical
$this->assertEquals($mapping1, $mapping2);

}
}

class SerializerMock
Expand Down

0 comments on commit 0b410cd

Please sign in to comment.