Name space
The client has a lot of namespaces and can often burst out of the functionality he manages. namespaces correspond to the endpoints of various elasticsearch management. The following is a list of the completed namespaces:
name Space |
function |
Indices () |
Index-centric statistics and information |
Nodes () |
Node-centric statistics and information
|
Cluster () |
Cluster-centric statistics and information
|
Snapshot () |
How to snapshot/restore your clusters and indicators |
Cat () |
Access to the Cat API (which is typically used for standalone access from the command line) |
Some methods can be used under different namespaces, giving you the same information, but grouped into different contexts. If you want to see how these namespaces work, let's look at the output of the _stats:
- $client = new Elasticsearch\client ();
- 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 takes place in three different namespaces. Sometimes methods require parameters. These parameters work just like the methods in other libraries.
For example, we can request statistics for a specific index or multiple index information.
- $client = new Elasticsearch\client ();
- 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);
Another example is how to add an alias to an existing index.
- $params [' body '] = Array (
- ' actions ' = = Array (
- Array (
- ' add ' = = Array (
- ' index ' = ' myindex ',
- ' Alias ' = ' myalias '
- )
- )
- )
- );
- $client->indices ()->updatealiases ($params);
Note how stats calls and Updatealias accept a variety of parameters, each of which is based on the needs of a particular API. The stats API requires only an index name, but Updatealias requires a body action.
elasticsearch-php namespaces