1[[namespaces]]
2=== Namespaces
3
4The client has a number of "namespaces", which generally expose administrative
5functionality. The namespaces correspond to the various administrative endpoints
6in {es}. This is a complete list of namespaces:
7
8
9[width="40%",options="header",frame="topbot"]
10|============================
11| Namespace    | Functionality
12| `indices()`  | Index-centric stats and info
13| `nodes()`    | Node-centric stats and info
14| `cluster()`  | Cluster-centric stats and info
15| `snapshot()` | Methods to snapshot/restore your cluster and indices
16| `cat()`      | Access to the Cat API (which is generally used standalone from the command line
17|============================
18
19Some methods are available in several different namespaces, which give you the
20same information but grouped into different contexts. To see how these
21namespaces work, let's look at the `_stats` output:
22
23
24[source,php]
25----
26$client = ClientBuilder::create()->build();
27
28// Index Stats
29// Corresponds to curl -XGET localhost:9200/_stats
30$response = $client->indices()->stats();
31
32// Node Stats
33// Corresponds to curl -XGET localhost:9200/_nodes/stats
34$response = $client->nodes()->stats();
35
36// Cluster Stats
37// Corresponds to curl -XGET localhost:9200/_cluster/stats
38$response = $client->cluster()->stats();
39----
40{zwsp} +
41
42As you can see, the same `stats()` call is made through three different
43namespaces. Sometimes the methods require parameters. These parameters work
44just like any other method in the library.
45
46For example, we can requests index stats about a specific index, or multiple
47indices:
48
49[source,php]
50----
51$client = ClientBuilder::create()->build();
52
53// Corresponds to curl -XGET localhost:9200/my_index/_stats
54$params['index'] = 'my_index';
55$response = $client->indices()->stats($params);
56
57// Corresponds to curl -XGET localhost:9200/my_index1,my_index2/_stats
58$params['index'] = array('my_index1', 'my_index2');
59$response = $client->indices()->stats($params);
60----
61{zwsp} +
62
63The following example shows how you can add an alias to an existing index:
64
65[source,php]
66----
67$params['body'] = array(
68    'actions' => array(
69        array(
70            'add' => array(
71                'index' => 'myindex',
72                'alias' => 'myalias'
73            )
74        )
75    )
76);
77$client->indices()->updateAliases($params);
78----
79
80Notice how both the `stats` calls and the updateAlias took a variety of
81parameters, each according to what the particular API requires. The `stats` API
82only requires an index name(s), while the `updateAlias` requires a body of
83actions.