lib/Elastica/Index.php
public function create(array $args = [], $options = null)
    {
        if (\is_bool($options) && $options) {
            try {
                $this->delete();
            } catch (ResponseException $e) {
                // Table can't be deleted, because doesn't exist
            }
        } elseif (\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;
                    default:
                        throw new InvalidException('Invalid option '.$key);
                        break;
                }
            }
        }

        $endpoint = new Create();
        $endpoint->setBody($args);

        return $this->requestEndpoint($endpoint);
    }
public function create(array $args = [], $options = null)
    {
        if (\is_bool($options) && $options) {
            try {
                $this->delete();
            } catch (ResponseException $e) {
                // Table can't be deleted, because doesn't exist
            }
        } elseif (\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;
                    default:
                        throw new InvalidException('Invalid option '.$key);
                        break;
                }
            }
        }

        $endpoint = new Create();
        $endpoint->setBody($args);

        return $this->requestEndpoint($endpoint);
    }
public function create ( array $ args = [ ] , $ options = null ) { if ( \ is_bool ( $ options ) && $ options ) { try { $ this -> delete ( ) ; } catch ( ResponseException $ e ) { // Table can't be deleted, because doesn't exist } } elseif ( \ 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 ; default : throw new InvalidException ( 'Invalid option ' . $ key ) ; break ; } } } $ endpoint = new Create ( ) ; $ endpoint -> setBody ( $ args ) ; return $ this -> requestEndpoint ( $ endpoint ) ; }
Creates a new index with the given arguments.

@see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html

@param array      $args    OPTIONAL Arguments to use
@param bool|array $options OPTIONAL
bool=> Deletes index first if already exists (default = false).
array => Associative array of options (option=>value)

@throws \Elastica\Exception\InvalidException
@throws \Elastica\Exception\ResponseException

@return \Elastica\Response Server response
Creates a new index with the given arguments .