You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the official PHP client for connecting to [Elasticsearch](https://www.elastic.co/elasticsearch/).
8
+
This is the official PHP client for [Elasticsearch](https://www.elastic.co/elasticsearch/).
9
9
10
10
## Contents
11
11
@@ -21,15 +21,18 @@ This is the official PHP client for connecting to [Elasticsearch](https://www.el
21
21
22
22
## Getting started 🐣
23
23
24
-
Using this client assumes that you have an [Elasticsearch](https://www.elastic.co/elasticsearch/) server installed and running.
24
+
Using this client assumes that you have an [Elasticsearch](https://www.elastic.co/elasticsearch/)
25
+
server installed and running.
25
26
26
-
You can install the client in your project by using composer:
27
+
You can install the client in your PHP project using [composer](https://getcomposer.org/):
27
28
28
29
```bash
29
30
composer require elasticsearch/elasticsearch
30
31
```
31
32
32
-
After the installation you can use the client as follows:
33
+
After the installation you can connect to Elasticsearch using the `ClientBuilder`
34
+
class. For instance, if your Elasticsearch is running on `localhost:9200`
35
+
you can use the following code:
33
36
34
37
```php
35
38
@@ -49,72 +52,79 @@ The `$response` is an object of `Elastic\Elasticsearch\Response\Elasticsearch`
49
52
class that implements `ElasticsearchInterface`, PSR-7 [ResponseInterface](https://www.php-fig.org/psr/psr-7/#33-psrhttpmessageresponseinterface)
50
53
and [ArrayAccess](https://www.php.net/manual/en/class.arrayaccess.php).
51
54
52
-
You can manage the response as PSR-7, as follows:
55
+
This means the `$response` is a [PSR-7](https://www.php-fig.org/psr/psr-7/)
56
+
object:
53
57
54
58
```php
55
59
echo $response->getStatusCode(); // 200
56
60
echo (string) $response->getBody(); // Response body in JSON
57
61
```
58
62
59
-
You can access the result of each endpoints using object or array interface,
60
-
as follows:
63
+
and also an "array", meaning you can access the response body as an
64
+
associative array, as follows:
65
+
61
66
62
67
```php
63
-
// Access body value as object
64
-
echo $response->version->number; // 8.0.0
65
-
// Access body value as array
66
68
echo $response['version']['number']; // 8.0.0
67
69
68
70
var_dump($response->asArray()); // response body content as array
71
+
```
72
+
73
+
Moreover, you can access the response body as object, string or bool:
74
+
75
+
```php
76
+
echo $response->version->number; // 8.0.0
77
+
69
78
var_dump($response->asObject()); // response body content as object
70
79
var_dump($response->asString()); // response body as string (JSON)
80
+
var_dump($response->asBool()); // true if HTTP response code between 200 and 300
71
81
```
72
82
73
83
## Configuration
74
84
75
-
Elasticsearch 8.0 offers security by default, that means it uses [TLS](https://en.wikipedia.org/wiki/Transport_Layer_Security)
76
-
for encrypt the communication between client and server.
85
+
Elasticsearch 8.0 offers [security by default](https://www.elastic.co/blog/introducing-simplified-elastic-stack-security),
86
+
that means it uses [TLS](https://en.wikipedia.org/wiki/Transport_Layer_Security)
87
+
for protect the communication between client and server.
77
88
78
89
In order to configure `elasticsearch-php` for connecting to Elasticsearch 8.0 we
79
-
need to have the certificate files (CA).
90
+
need to have the certificate authority file (CA).
80
91
81
92
You can install Elasticsearch in different ways, for instance using [Docker](https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html)
0 commit comments