Skip to content

Commit

Permalink
Drill into Type::getMapping result for convenience
Browse files Browse the repository at this point in the history
  • Loading branch information
mal committed Apr 20, 2014
1 parent 063f837 commit fa5612a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 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
- Handling of HasChild type parsing bug #585
- Consolidate Index getMapping tests
- Fix Type::getMapping when using an aliased index #588
- Strip useless nesting from Type::getMapping result

2014-04-19
- Release v1.1.1.0
Expand Down
4 changes: 2 additions & 2 deletions lib/Elastica/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ public function getMapping()
$data = $response->getData();

$mapping = array_shift($data);
if (isset($mapping['mappings'])) {
return $mapping['mappings'];
if (isset($mapping['mappings'][$this->getName()]['properties'])) {
return $mapping['mappings'][$this->getName()]['properties'];
}

return array();
Expand Down
15 changes: 7 additions & 8 deletions test/lib/Elastica/Test/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,17 @@ public function testNoSource()
$type = new Type($index, 'user');
$mapping = new Mapping($type, array(
'id' => array('type' => 'integer', 'store' => 'yes'),
'username' => array('type' => 'string', 'store' => 'no'),
'username' => array('type' => 'string', 'store' => 'no')
));
$mapping->setSource(array('enabled' => false));
$type->setMapping($mapping);

$mapping = $type->getMapping();

$this->assertArrayHasKey('user', $mapping);
$this->assertArrayHasKey('properties', $mapping['user']);
$this->assertArrayHasKey('id', $mapping['user']['properties']);
$this->assertArrayHasKey('type', $mapping['user']['properties']['id']);
$this->assertEquals('integer', $mapping['user']['properties']['id']['type']);
$this->assertEquals(array(
'id' => array('type' => 'integer', 'store' => true),
'username' => array('type' => 'string')
), $mapping);

// Adds 1 document to the index
$doc1 = new Document(1,
Expand Down Expand Up @@ -787,7 +786,7 @@ public function testGetMapping() {
$client = $index->getClient();

$this->assertEquals(
array('test-type' => array('properties' => $expect)),
$expect,
$client->getIndex($indexName)->getType($typeName)->getMapping()
);
}
Expand All @@ -808,7 +807,7 @@ public function testGetMappingAlias() {
$client = $index->getClient();

$this->assertEquals(
array('test-alias-type' => array('properties' => $expect)),
$expect,
$client->getIndex($aliasName)->getType($typeName)->getMapping()
);
}
Expand Down

0 comments on commit fa5612a

Please sign in to comment.