/**
  * Builds a Mapping Collection from the configured node types
  *
  * @param \Flowpack\ElasticSearch\Domain\Model\Index $index
  * @return \Flowpack\ElasticSearch\Mapping\MappingCollection<\Flowpack\ElasticSearch\Domain\Model\Mapping>
  */
 public function buildMappingInformation(Index $index)
 {
     $this->lastMappingErrors = new \TYPO3\Flow\Error\Result();
     $mappings = new MappingCollection(MappingCollection::TYPE_ENTITY);
     /** @var NodeType $nodeType */
     foreach ($this->nodeTypeManager->getNodeTypes() as $nodeTypeName => $nodeType) {
         if ($nodeTypeName === 'unstructured' || $nodeType->isAbstract()) {
             continue;
         }
         $type = $index->findType(self::convertNodeTypeNameToMappingName($nodeTypeName));
         $mapping = new Mapping($type);
         // http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-root-object-type.html#_dynamic_templates
         // 'not_analyzed' is necessary
         $mapping->addDynamicTemplate('dimensions', array('path_match' => '__dimensionCombinations.*', 'match_mapping_type' => 'string', 'mapping' => array('type' => 'string', 'index' => 'not_analyzed')));
         foreach ($nodeType->getProperties() as $propertyName => $propertyConfiguration) {
             if (isset($propertyConfiguration['search']) && isset($propertyConfiguration['search']['elasticSearchMapping'])) {
                 if (is_array($propertyConfiguration['search']['elasticSearchMapping'])) {
                     $mapping->setPropertyByPath($propertyName, $propertyConfiguration['search']['elasticSearchMapping']);
                 }
             } elseif (isset($propertyConfiguration['type']) && isset($this->defaultConfigurationPerType[$propertyConfiguration['type']]['elasticSearchMapping'])) {
                 if (is_array($this->defaultConfigurationPerType[$propertyConfiguration['type']]['elasticSearchMapping'])) {
                     $mapping->setPropertyByPath($propertyName, $this->defaultConfigurationPerType[$propertyConfiguration['type']]['elasticSearchMapping']);
                 }
             } else {
                 $this->lastMappingErrors->addWarning(new \TYPO3\Flow\Error\Warning('Node Type "' . $nodeTypeName . '" - property "' . $propertyName . '": No ElasticSearch Mapping found.'));
             }
         }
         $mappings->add($mapping);
     }
     return $mappings;
 }
 /**
  * set to final because this is an important step which may not be overridden.
  */
 public final function tearDown()
 {
     parent::tearDown();
     if ($this->removeIndexOnTearDown === TRUE) {
         $this->testingIndex->delete();
     }
 }
 /**
  * Refresh an index in ElasticSearch
  *
  * @param string $indexName The name of the index to be removed
  * @param string $clientName The client name to use
  */
 public function refreshCommand($indexName, $clientName = null)
 {
     if (!in_array($indexName, $this->indexInformer->getAllIndexNames())) {
         $this->outputFormatted("The index <b>%s</b> is not configured in the current application", array($indexName));
     }
     $client = $this->clientFactory->create($clientName);
     try {
         $index = new Index($indexName, $client);
         if (!$index->exists()) {
             $this->outputFormatted("The index <b>%s</b> does not exists", array($indexName));
             $this->quit(1);
         }
         $index->refresh();
         $this->outputFormatted("Index <b>%s</b> refreshed with success", array($indexName));
     } catch (Exception $exception) {
         $this->outputFormatted("Unable to refresh an index named: <b>%s</b>", array($indexName));
         $this->quit(1);
     }
 }
 /**
  * @param string $method
  * @param string $path
  * @param array $arguments
  * @param string $content
  *
  * @return \Flowpack\ElasticSearch\Transfer\Response
  */
 public function request($method, $path = null, $arguments = array(), $content = null)
 {
     $path = '/' . $this->name . ($path ?: '');
     return $this->index->request($method, $path, $arguments, $content);
 }