IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Create an index
editCreate an index
editThe index operations are all contained under a distinct namespace, separated from other methods that are on the root client object. As an example, let’s create a new index:
$client = new Elasticsearch\Client(); $indexParams['index'] = 'my_index'; //index $client->indices()->create($indexParams);
You can, of course, specify any parameters that would normally be included in a new index creation API. All parameters that would normally go in the request body are located in the body associative array:
$client = new Elasticsearch\Client(); $indexParams['index'] = 'my_index'; // Index Settings $indexParams['body']['settings']['number_of_shards'] = 3; $indexParams['body']['settings']['number_of_replicas'] = 2; // Example Index Mapping $myTypeMapping = array( '_source' => array( 'enabled' => true ), 'properties' => array( 'first_name' => array( 'type' => 'string', 'analyzer' => 'standard' ), 'age' => array( 'type' => 'integer' ) ) ); $indexParams['body']['mappings']['my_type'] = $myTypeMapping; // Create the index $client->indices()->create($indexParams);