- PHP Client: other versions:
- Overview
- Quickstart
- Installation
- Configuration
- Inline Host Configuration
- Extended Host Configuration
- Authorization and Encryption
- Set retries
- Enabling the Logger
- Configure the HTTP Handler
- Setting the Connection Pool
- Setting the Connection Selector
- Setting the Serializer
- Setting a custom ConnectionFactory
- Set the Endpoint closure
- Building the client from a configuration hash
- Per-request configuration
- Future Mode
- Dealing with JSON Arrays and Objects in PHP
- Index Management Operations
- Indexing Documents
- Getting Documents
- Updating Documents
- Deleting documents
- Search Operations
- Namespaces
- Security
- Connection Pool
- Selectors
- Serializers
- PHP Version Requirement
- Breaking changes from 5.x
- Community DSLs
- Community Integrations
- Reference - Endpoints
- Elasticsearch\Client
- Elasticsearch\ClientBuilder
- Elasticsearch\Namespaces\CatNamespace
- Elasticsearch\Namespaces\ClusterNamespace
- Elasticsearch\Namespaces\IndicesNamespace
- Elasticsearch\Namespaces\IngestNamespace
- Elasticsearch\Namespaces\NodesNamespace
- Elasticsearch\Namespaces\RemoteNamespace
- Elasticsearch\Namespaces\SnapshotNamespace
- Elasticsearch\Namespaces\TasksNamespace
Namespaces
editNamespaces
editThe client has a number of "namespaces", which generally expose administrative functionality. The namespaces correspond to the various administrative endpoints in Elasticsearch. This is a complete list of namespaces:
Namespace | Functionality |
---|---|
|
Index-centric stats and info |
|
Node-centric stats and info |
|
Cluster-centric stats and info |
|
Methods to snapshot/restore your cluster and indices |
|
Access to the Cat API (which is generally used standalone from the command line |
Some methods are available in several different namespaces, which give you
the same information but grouped into different contexts. To see how these
namespaces work, let’s look at the _stats
output:
$client = ClientBuilder::create()->build(); // Index Stats // Corresponds to curl -XGET localhost:9200/_stats $response = $client->indices()->stats(); // Node Stats // Corresponds to curl -XGET localhost:9200/_nodes/stats $response = $client->nodes()->stats(); // Cluster Stats // Corresponds to curl -XGET localhost:9200/_cluster/stats $response = $client->cluster()->stats();
As you can see, the same stats()
call is made through three different
namespaces. Sometimes the methods require parameters. These parameters work
just like any other method in the library.
For example, we can requests index stats about a specific index, or multiple indices:
$client = ClientBuilder::create()->build(); // Corresponds to curl -XGET localhost:9200/my_index/_stats $params['index'] = 'my_index'; $response = $client->indices()->stats($params); // Corresponds to curl -XGET localhost:9200/my_index1,my_index2/_stats $params['index'] = array('my_index1', 'my_index2'); $response = $client->indices()->stats($params);
As another example, here is how you might add an alias to an existing index:
$params['body'] = array( 'actions' => array( array( 'add' => array( 'index' => 'myindex', 'alias' => 'myalias' ) ) ) ); $client->indices()->updateAliases($params);
Notice how both the stats
calls and the updateAlias took a variety of parameters,
each according to what the particular API requires. The stats
API only requires
an index name(s), while the updateAlias
requires a body of actions.
ElasticON events are back!
Learn about the Elastic Search AI Platform from the experts at our live events.
Register now