Ignore TypeMissingException when resetting a single type. This allows to create new types without having to recreate the whole index.
This commit is contained in:
parent
33f85bec22
commit
726892c586
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace FOS\ElasticaBundle;
|
||||
|
||||
use Elastica\Exception\ResponseException;
|
||||
use Elastica\Type\Mapping;
|
||||
|
||||
/**
|
||||
|
@ -59,7 +60,13 @@ class Resetter
|
|||
}
|
||||
|
||||
$type = $indexConfig['index']->getType($typeName);
|
||||
$type->delete();
|
||||
try {
|
||||
$type->delete();
|
||||
} catch (ResponseException $e) {
|
||||
if (strpos($e->getMessage(), 'TypeMissingException') !== 0) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
$mapping = $this->createMapping($indexConfig['config']['mappings'][$typeName]);
|
||||
$type->setMapping($mapping);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace FOS\ElasticaBundle\Tests\Resetter;
|
||||
|
||||
use Elastica\Exception\ResponseException;
|
||||
use Elastica\Request;
|
||||
use Elastica\Response;
|
||||
use FOS\ElasticaBundle\Resetter;
|
||||
use Elastica\Type\Mapping;
|
||||
|
||||
|
@ -130,6 +133,32 @@ class ResetterTest extends \PHPUnit_Framework_TestCase
|
|||
$resetter->resetIndexType('foo', 'c');
|
||||
}
|
||||
|
||||
public function testResetIndexTypeIgnoreTypeMissingException()
|
||||
{
|
||||
$type = $this->getMockElasticaType();
|
||||
|
||||
$this->indexConfigsByName['foo']['index']->expects($this->once())
|
||||
->method('getType')
|
||||
->with('a')
|
||||
->will($this->returnValue($type));
|
||||
|
||||
$type->expects($this->once())
|
||||
->method('delete')
|
||||
->will($this->throwException(new ResponseException(
|
||||
new Request(''),
|
||||
new Response(array('error' => 'TypeMissingException[[de_20131022] type[bla] missing]', 'status' => 404)))
|
||||
));
|
||||
|
||||
$mapping = Mapping::create($this->indexConfigsByName['foo']['config']['mappings']['a']['properties']);
|
||||
$mapping->setParam('dynamic_templates', $this->indexConfigsByName['foo']['config']['mappings']['a']['dynamic_templates']);
|
||||
$type->expects($this->once())
|
||||
->method('setMapping')
|
||||
->with($mapping);
|
||||
|
||||
$resetter = new Resetter($this->indexConfigsByName);
|
||||
$resetter->resetIndexType('foo', 'a');
|
||||
}
|
||||
|
||||
public function testIndexMappingForParent()
|
||||
{
|
||||
$type = $this->getMockElasticaType();
|
||||
|
|
Loading…
Reference in a new issue