add _parent in mapping during index reset
This commit is contained in:
parent
10eae2f254
commit
79eb062cf7
2 changed files with 56 additions and 2 deletions
22
Resetter.php
22
Resetter.php
|
|
@ -58,7 +58,27 @@ class Resetter
|
|||
|
||||
$type = $indexConfig['index']->getType($typeName);
|
||||
$type->delete();
|
||||
$type->setMapping($indexConfig['config']['mappings'][$typeName]['properties']);
|
||||
$mapping = $this->createMapping($indexConfig['config']['mappings'][$typeName]);
|
||||
$type->setMapping($mapping);
|
||||
}
|
||||
|
||||
/**
|
||||
* create type mapping object
|
||||
*
|
||||
* @param array $indexConfig
|
||||
* @return Elastica_Type_Mapping
|
||||
*/
|
||||
protected function createMapping($indexConfig)
|
||||
{
|
||||
$mapping = \Elastica_Type_Mapping::create($indexConfig['properties']);
|
||||
|
||||
foreach($indexConfig['properties'] as $field => $type) {
|
||||
if (!empty($type['_parent']) && $type['_parent'] !== '~') {
|
||||
$mapping->setParam('_parent', array('type' => $type['_parent']['type']));
|
||||
}
|
||||
}
|
||||
|
||||
return $mapping;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -29,6 +29,17 @@ class ResetterTest extends \PHPUnit_Framework_TestCase
|
|||
),
|
||||
),
|
||||
),
|
||||
'parent' => array(
|
||||
'index' => $this->getMockElasticaIndex(),
|
||||
'config' => array(
|
||||
'mappings' => array(
|
||||
'a' => array('properties' => array(
|
||||
'field_1' => array('_parent' => array('type' => 'b', 'identifier' => 'id')),
|
||||
'field_2' => array())),
|
||||
'b' => array('properties' => array()),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -80,9 +91,10 @@ class ResetterTest extends \PHPUnit_Framework_TestCase
|
|||
$type->expects($this->once())
|
||||
->method('delete');
|
||||
|
||||
$mapping = \Elastica_Type_Mapping::create($this->indexConfigsByName['foo']['config']['mappings']['a']['properties']);
|
||||
$type->expects($this->once())
|
||||
->method('setMapping')
|
||||
->with($this->indexConfigsByName['foo']['config']['mappings']['a']['properties']);
|
||||
->with($mapping);
|
||||
|
||||
$resetter = new Resetter($this->indexConfigsByName);
|
||||
$resetter->resetIndexType('foo', 'a');
|
||||
|
|
@ -106,6 +118,28 @@ class ResetterTest extends \PHPUnit_Framework_TestCase
|
|||
$resetter->resetIndexType('foo', 'c');
|
||||
}
|
||||
|
||||
public function testIndexMappingForParent()
|
||||
{
|
||||
$type = $this->getMockElasticaType();
|
||||
|
||||
$this->indexConfigsByName['parent']['index']->expects($this->once())
|
||||
->method('getType')
|
||||
->with('a')
|
||||
->will($this->returnValue($type));
|
||||
|
||||
$type->expects($this->once())
|
||||
->method('delete');
|
||||
|
||||
$mapping = \Elastica_Type_Mapping::create($this->indexConfigsByName['parent']['config']['mappings']['a']['properties']);
|
||||
$mapping->setParam('_parent', array('type' => 'b'));
|
||||
$type->expects($this->once())
|
||||
->method('setMapping')
|
||||
->with($mapping);
|
||||
|
||||
$resetter = new Resetter($this->indexConfigsByName);
|
||||
$resetter->resetIndexType('parent', 'a');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Elastica_Index
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue