Elastica\Index::create PHP Method

create() public method

Creates a new index with the given arguments.
public create ( array $args = [], boolean | array $options = null ) : Response
$args array OPTIONAL Arguments to use
$options boolean | array OPTIONAL bool=> Deletes index first if already exists (default = false). array => Associative array of options (option=>value)
return Response Server response
    public function create(array $args = [], $options = null)
    {
        $path = '';
        $query = [];
        if (is_bool($options)) {
            if ($options) {
                try {
                    $this->delete();
                } catch (ResponseException $e) {
                    // Table can't be deleted, because doesn't exist
                }
            }
        } else {
            if (is_array($options)) {
                foreach ($options as $key => $value) {
                    switch ($key) {
                        case 'recreate':
                            try {
                                $this->delete();
                            } catch (ResponseException $e) {
                                // Table can't be deleted, because doesn't exist
                            }
                            break;
                        case 'routing':
                            $query = ['routing' => $value];
                            break;
                        default:
                            throw new InvalidException('Invalid option ' . $key);
                            break;
                    }
                }
            }
        }
        return $this->request($path, Request::PUT, $args, $query);
    }

Usage Example

Beispiel #1
0
 /**
  * Create the test index before tests run.
  */
 protected static function createIndex()
 {
     self::$index->create(['analysis' => ['analyzer' => MappingFactory::getCustomAnalyzers()]], true);
     $type = self::$index->getType('message');
     $mapping = (new MappingFactory())->create(EmailMessage::schema(), 'english');
     $mapping->setType($type);
     $mapping->send();
 }
All Usage Examples Of Elastica\Index::create