/** * @return array */ public function getMetaData() { $metaData = []; try { $mapping = $this->index->getMapping(); if (isset($mapping['page']) && isset($mapping['page']['_meta'])) { $metaData = $mapping['page']['_meta']; } } catch (ResponseException $e) { // legal catch, if no mapping found (fresh installation etc) we still want to show empty meta data } return $metaData; }
/** * Check that the mapping returned from Elasticsearch is as we want it. * * @param array $requiredMappings the mappings we want * @return bool is the mapping good enough for us? */ private function checkMapping($requiredMappings) { $actualMappings = $this->index->getMapping(); $this->output("\n"); $this->outputIndented("\tValidating mapping..."); if ($this->checkConfig($actualMappings, $requiredMappings)) { $this->output("ok\n"); return true; } else { $this->output("different..."); return false; } }
/** * Copies type mappings and documents from an old index to a new index. * * @see \Elastica\Tool\CrossIndex::reindex() * * @param \Elastica\Index $oldIndex * @param \Elastica\Index $newIndex * @param array $options keys: CrossIndex::OPTION_* constants * * @return \Elastica\Index The new index object */ public static function copy(Index $oldIndex, Index $newIndex, array $options = array()) { // normalize types to array of string $types = array(); if (isset($options[self::OPTION_TYPE])) { $types = $options[self::OPTION_TYPE]; $types = is_array($types) ? $types : array($types); $types = array_map(function ($type) { if ($type instanceof Type) { $type = $type->getName(); } return (string) $type; }, $types); } // copy mapping foreach ($oldIndex->getMapping() as $type => $mapping) { if (!empty($types) && !in_array($type, $types, true)) { continue; } $type = new Type($newIndex, $type); $type->setMapping($mapping['properties']); } // copy documents return self::reindex($oldIndex, $newIndex, $options); }