Skip to content

Commit fa5612a

Browse files
committed
Drill into Type::getMapping result for convenience
1 parent 063f837 commit fa5612a

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

changes.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGES
44
- Handling of HasChild type parsing bug #585
55
- Consolidate Index getMapping tests
66
- Fix Type::getMapping when using an aliased index #588
7+
- Strip useless nesting from Type::getMapping result
78

89
2014-04-19
910
- Release v1.1.1.0

lib/Elastica/Type.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ public function getMapping()
300300
$data = $response->getData();
301301

302302
$mapping = array_shift($data);
303-
if (isset($mapping['mappings'])) {
304-
return $mapping['mappings'];
303+
if (isset($mapping['mappings'][$this->getName()]['properties'])) {
304+
return $mapping['mappings'][$this->getName()]['properties'];
305305
}
306306

307307
return array();

test/lib/Elastica/Test/TypeTest.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,17 @@ public function testNoSource()
141141
$type = new Type($index, 'user');
142142
$mapping = new Mapping($type, array(
143143
'id' => array('type' => 'integer', 'store' => 'yes'),
144-
'username' => array('type' => 'string', 'store' => 'no'),
144+
'username' => array('type' => 'string', 'store' => 'no')
145145
));
146146
$mapping->setSource(array('enabled' => false));
147147
$type->setMapping($mapping);
148148

149149
$mapping = $type->getMapping();
150150

151-
$this->assertArrayHasKey('user', $mapping);
152-
$this->assertArrayHasKey('properties', $mapping['user']);
153-
$this->assertArrayHasKey('id', $mapping['user']['properties']);
154-
$this->assertArrayHasKey('type', $mapping['user']['properties']['id']);
155-
$this->assertEquals('integer', $mapping['user']['properties']['id']['type']);
151+
$this->assertEquals(array(
152+
'id' => array('type' => 'integer', 'store' => true),
153+
'username' => array('type' => 'string')
154+
), $mapping);
156155

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

789788
$this->assertEquals(
790-
array('test-type' => array('properties' => $expect)),
789+
$expect,
791790
$client->getIndex($indexName)->getType($typeName)->getMapping()
792791
);
793792
}
@@ -808,7 +807,7 @@ public function testGetMappingAlias() {
808807
$client = $index->getClient();
809808

810809
$this->assertEquals(
811-
array('test-alias-type' => array('properties' => $expect)),
810+
$expect,
812811
$client->getIndex($aliasName)->getType($typeName)->getMapping()
813812
);
814813
}

0 commit comments

Comments
 (0)