/**
  * Rebuild Mapping
  *
  * This will delete and then re-add
  * the mapping for this model.
  *
  * @return array
  */
 public static function rebuildMapping()
 {
     $instance = new static();
     // If the mapping exists, let's delete it.
     if ($instance->mappingExists()) {
         $instance->deleteMapping();
     }
     // Don't need ignore conflicts because if we
     // just removed the mapping there shouldn't
     // be any conflicts.
     return $instance->putMapping();
 }
 /**
  * Create Index
  *
  * @param bool $new
  * @param bool $seamless
  * @param int $shards
  * @param int $replicas
  * @return array
  */
 public static function createIndex($new = true, $shards = 1, $replicas = 0)
 {
     $instance = new static();
     $client = $instance->getElasticSearchClient();
     $timestamp = time();
     $base = $instance->getIndexName();
     $index = ['name' => $base . '_' . $timestamp, 'read' => $base . '_read', 'write' => $base . '_write'];
     $params = array('index' => $index['name']);
     $params['body']['settings']['number_of_shards'] = $shards;
     $params['body']['settings']['number_of_replicas'] = $replicas;
     $client->indices()->create($params);
     if ($new) {
         $instance->createAlias($index['read'], $index['name']);
         $instance->createAlias($index['write'], $index['name']);
     } else {
         $instance->updateAlias($index['write'], $index['name']);
     }
     $instance->putMapping();
 }
Example #3
0
 /**
  * Rebuilds mappings.
  *
  * @return array
  */
 public static function rebuildMapping()
 {
     $instance = new static();
     if ($instance->hasMapping()) {
         $instance->deleteMapping();
     }
     return $instance->putMapping();
 }