/** * * Create single index * @param \Elastica\Client $client * @param string $indexName * @param array $params * @param boolean $recreate * @throws Exception */ protected function createSingleIndex(\Elastica\Client $client, $indexName, $params = array(), $recreate = false) { try { // create an elastic index $settings = $this->getIndexSetting($indexName, $params); $index = new \Elastica\Index($client, $indexName); $index->create($settings, $recreate); } catch (Exception $e) { // ignore the IndexAlreadyExistsException exception if (strpos($e->getMessage(), 'IndexAlreadyExistsException') === false) { throw $e; } } return $index; }
/** * {@inheritdoc} */ public function store(array $data, array $keys, $namespace) { $type = $this->index->getType($namespace); // Build mapping $mapping = new Mapping(); $mapping->setType($type); $mapping->setProperties(array('hash' => array('type' => 'string', 'include_in_all' => true), 'keys' => array('type' => 'string', 'include_in_all' => true))); $mapping->send(); // Build document $document = new Document('', array_merge($data, array('hash' => $this->getHash($data, $keys), 'keys' => $keys))); $type->addDocument($document); $this->index->refresh(); }
/** * Creates a new Type object * * @param Elastica\Index $index the Index where you want to create your Type * @param string $name Type name * * @return Elastica\Type */ function createType($index, $name) { return $index->getType($name); }