public function testMappingBuilderStoreProperty()
 {
     $typeConfig = new TypeConfig('typename', ['properties' => ['storeless' => ['type' => 'string'], 'stored' => ['type' => 'string', 'store' => true], 'unstored' => ['type' => 'string', 'store' => false]]]);
     $mapping = $this->builder->buildTypeMapping($typeConfig);
     $this->assertArrayNotHasKey('store', $mapping['properties']['storeless']);
     $this->assertArrayHasKey('store', $mapping['properties']['stored']);
     $this->assertTrue($mapping['properties']['stored']['store']);
     $this->assertArrayHasKey('store', $mapping['properties']['unstored']);
     $this->assertFalse($mapping['properties']['unstored']['store']);
 }
 public function testMappingBuilderStoreProperty()
 {
     $typeConfig = new TypeConfig('typename', array('properties' => array('storeless' => array('type' => 'string'), 'stored' => array('type' => 'string', 'store' => true), 'unstored' => array('type' => 'string', 'store' => false)), '_parent' => array('type' => 'parent_type', 'identifier' => 'name', 'property' => 'parent_property')));
     $mapping = $this->builder->buildTypeMapping($typeConfig);
     $this->assertArrayNotHasKey('store', $mapping['properties']['storeless']);
     $this->assertArrayHasKey('store', $mapping['properties']['stored']);
     $this->assertTrue($mapping['properties']['stored']['store']);
     $this->assertArrayHasKey('store', $mapping['properties']['unstored']);
     $this->assertFalse($mapping['properties']['unstored']['store']);
     $this->assertArrayHasKey('_parent', $mapping);
     $this->assertArrayNotHasKey('identifier', $mapping['_parent']);
     $this->assertArrayNotHasKey('property', $mapping['_parent']);
 }
Esempio n. 3
0
 /**
  * Deletes and recreates a mapping type for the named index.
  *
  * @param string $indexName
  * @param string $typeName
  *
  * @throws \InvalidArgumentException if no index or type mapping exists for the given names
  * @throws ResponseException
  */
 public function resetIndexType($indexName, $typeName)
 {
     $typeConfig = $this->configManager->getTypeConfiguration($indexName, $typeName);
     $index = $this->indexManager->getIndex($indexName);
     $type = $index->getType($typeName);
     $indexConfig = $this->configManager->getIndexConfiguration($indexName);
     $settings = $indexConfig->getSettings();
     $event = new TypeResetEvent($indexName, $typeName);
     $this->dispatcher->dispatch(TypeResetEvent::PRE_TYPE_RESET, $event);
     try {
         $type->delete();
     } catch (ResponseException $e) {
         if (strpos($e->getMessage(), 'TypeMissingException') === false) {
             throw $e;
         }
     }
     if (!empty($settings)) {
         $index->close();
         $index->setSettings($settings);
         $index->open();
     }
     $mapping = new Mapping();
     foreach ($this->mappingBuilder->buildTypeMapping($typeConfig) as $name => $field) {
         $mapping->setParam($name, $field);
     }
     $type->setMapping($mapping);
     $this->dispatcher->dispatch(TypeResetEvent::POST_TYPE_RESET, $event);
 }
Esempio n. 4
0
 /**
  * Deletes and recreates the named index. If populating, creates a new index
  * with a randomised name for an alias to be set after population.
  *
  * @param string $indexName
  * @param bool   $populating
  * @param bool   $force      If index exists with same name as alias, remove it
  *
  * @throws \InvalidArgumentException if no index exists for the given name
  */
 public function resetIndex($indexName, $populating = false, $force = false)
 {
     $indexConfig = $this->configManager->getIndexConfiguration($indexName);
     $index = $this->indexManager->getIndex($indexName);
     $event = new IndexResetEvent($indexName, $populating, $force);
     $this->dispatcher->dispatch(IndexResetEvent::PRE_INDEX_RESET, $event);
     if ($indexConfig->isUseAlias()) {
         $this->aliasProcessor->setRootName($indexConfig, $index);
     }
     $mapping = $this->mappingBuilder->buildIndexMapping($indexConfig);
     $index->create($mapping, true);
     if (!$populating and $indexConfig->isUseAlias()) {
         $this->aliasProcessor->switchIndexAlias($indexConfig, $index, $force);
     }
     $this->dispatcher->dispatch(IndexResetEvent::POST_INDEX_RESET, $event);
 }
Esempio n. 5
0
 /**
  * Deletes and recreates a mapping type for the named index
  *
  * @param string $indexName
  * @param string $typeName
  * @throws \InvalidArgumentException if no index or type mapping exists for the given names
  * @throws ResponseException
  */
 public function resetIndexType($indexName, $typeName)
 {
     $typeConfig = $this->configManager->getTypeConfiguration($indexName, $typeName);
     $type = $this->indexManager->getIndex($indexName)->getType($typeName);
     try {
         $type->delete();
     } catch (ResponseException $e) {
         if (strpos($e->getMessage(), 'TypeMissingException') === false) {
             throw $e;
         }
     }
     $mapping = new Mapping();
     foreach ($this->mappingBuilder->buildTypeMapping($typeConfig) as $name => $field) {
         $mapping->setParam($name, $field);
     }
     $type->setMapping($mapping);
 }
Esempio n. 6
0
 /**
  * Deletes and recreates a mapping type for the named index.
  *
  * @param string $indexName
  * @param string $typeName
  *
  * @throws \InvalidArgumentException if no index or type mapping exists for the given names
  * @throws ResponseException
  */
 public function resetIndexType($indexName, $typeName)
 {
     $typeConfig = $this->configManager->getTypeConfiguration($indexName, $typeName);
     $this->resetIndex($indexName, true);
     $index = $this->indexManager->getIndex($indexName);
     $type = $index->getType($typeName);
     $event = new TypeResetEvent($indexName, $typeName);
     $this->dispatcher->dispatch(TypeResetEvent::PRE_TYPE_RESET, $event);
     if (!empty($settings)) {
         unset($settings['number_of_shards']);
         $index->close();
         $index->setSettings($settings);
         $index->open();
     }
     $mapping = new Mapping();
     foreach ($this->mappingBuilder->buildTypeMapping($typeConfig) as $name => $field) {
         $mapping->setParam($name, $field);
     }
     $type->setMapping($mapping);
     $this->dispatcher->dispatch(TypeResetEvent::POST_TYPE_RESET, $event);
 }