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 = ClientBuilder::create()->build(); $params = [ 'index' => 'my_index' ]; // Create the index $response = $client->indices()->create($params);
You can 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 parameter:
$client = ClientBuilder::create()->build(); $params = [ 'index' => 'my_index', 'body' => [ 'settings' => [ 'number_of_shards' => 3, 'number_of_replicas' => 2 ], 'mappings' => [ 'my_type' => [ '_source' => [ 'enabled' => true ], 'properties' => [ 'first_name' => [ 'type' => 'string', 'analyzer' => 'standard' ], 'age' => [ 'type' => 'integer' ] ] ] ] ] ]; // Create the index with mappings and settings now $response = $client->indices()->create($params);