Skip to content

Commit 2607793

Browse files
committed
Prep for v8.0.0
1 parent 620040d commit 2607793

File tree

3 files changed

+42
-32
lines changed

3 files changed

+42
-32
lines changed

README.md

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Elasticsearch PHP client
55

66
[![Build status](https://github.com/elastic/elasticsearch-php/workflows/PHP%20test/badge.svg)](https://github.com/elastic/elasticsearch-php/actions) [![Latest Stable Version](https://poser.pugx.org/elasticsearch/elasticsearch/v/stable)](https://packagist.org/packages/elasticsearch/elasticsearch) [![Total Downloads](https://poser.pugx.org/elasticsearch/elasticsearch/downloads)](https://packagist.org/packages/elasticsearch/elasticsearch)
77

8-
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/).
99

1010
## Contents
1111

@@ -21,15 +21,18 @@ This is the official PHP client for connecting to [Elasticsearch](https://www.el
2121

2222
## Getting started 🐣
2323

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.
2526

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/):
2728

2829
```bash
2930
composer require elasticsearch/elasticsearch
3031
```
3132

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:
3336

3437
```php
3538

@@ -49,72 +52,79 @@ The `$response` is an object of `Elastic\Elasticsearch\Response\Elasticsearch`
4952
class that implements `ElasticsearchInterface`, PSR-7 [ResponseInterface](https://www.php-fig.org/psr/psr-7/#33-psrhttpmessageresponseinterface)
5053
and [ArrayAccess](https://www.php.net/manual/en/class.arrayaccess.php).
5154

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:
5357

5458
```php
5559
echo $response->getStatusCode(); // 200
5660
echo (string) $response->getBody(); // Response body in JSON
5761
```
5862

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+
6166

6267
```php
63-
// Access body value as object
64-
echo $response->version->number; // 8.0.0
65-
// Access body value as array
6668
echo $response['version']['number']; // 8.0.0
6769

6870
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+
6978
var_dump($response->asObject()); // response body content as object
7079
var_dump($response->asString()); // response body as string (JSON)
80+
var_dump($response->asBool()); // true if HTTP response code between 200 and 300
7181
```
7282

7383
## Configuration
7484

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.
7788

7889
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).
8091

8192
You can install Elasticsearch in different ways, for instance using [Docker](https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html)
8293
you need to execute the followind command:
8394

8495
```bash
8596
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.0.1
8697
```
87-
88-
Once you have the docker image installed you can execute Elasticsearch `8.0.1`,
89-
for instance using a single-node Elasticsearch cluster, as follows:
98+
Once you have the docker image installed you can execute Elasticsearch,
99+
for instance using a single-node cluster configuration, as follows:
90100

91101
```bash
92102
docker network create elastic
93103
docker run --name es01 --net elastic -p 9200:9200 -p 9300:9300 -it docker.elastic.co/elasticsearch/elasticsearch:8.0.1
94104
```
95105

96-
This command will create an `elastic` Docker network and start Elasticsearch
97-
using the default port `9200`.
106+
This command creates an `elastic` Docker network and start Elasticsearch
107+
using the port `9200` (default).
98108

99-
During the start of Elasticsearch a password is generated for the `elastic` user
100-
and output to the terminal (you might need to scroll back a bit in the terminal
101-
to view it). Please copy it since we will need to connect to Elasticsearch.
109+
When you run the docker imnage a password is generated for the `elastic` user
110+
and it's printed to the terminal (you might need to scroll back a bit in the terminal
111+
to view it). You have to copy it since we will need to connect to Elasticsearch.
102112

103-
In order to get the `http_ca.crt` file certificate, you need to copy it from the
104-
Docker instance, using the following command:
113+
Now that Elasticsearch is running we can get the `http_ca.crt` file certificate.
114+
We need to copy it from the docker instance, using the following command:
105115

106116
```bash
107117
docker cp es01:/usr/share/elasticsearch/config/certs/http_ca.crt .
108118
```
109119

110-
Once you have the `http_ca.crt` certificate and the `password` copied during the
111-
start of Elasticsearch we can use it to connect using `elasticsearch-php`
120+
Once we have the `http_ca.crt` certificate and the `password`, copied during the
121+
start of Elasticsearch, we can use it to connect with `elasticsearch-php`
112122
as follows:
113123

114124
```php
115125
$client = ClientBuilder::create()
116126
->setHosts(['https://localhost:9200'])
117-
->setBasicAuthentication('elastic', 'password-here')
127+
->setBasicAuthentication('elastic', 'password copied during Elasticsearch start')
118128
->setCABundle('path/to/http_ca.crt')
119129
->build();
120130
```
@@ -124,10 +134,10 @@ read the official documentation [here](https://www.elastic.co/guide/en/elasticse
124134

125135
### Use Elastic Cloud
126136

127-
You can use [Elastic Cloud](https://www.elastic.co/cloud/) as server to connect using `elasticsearch-php`.
137+
You can use [Elastic Cloud](https://www.elastic.co/cloud/) as server with `elasticsearch-php`.
128138
Elastic Cloud is the PaaS solution offered by [Elastic](https://www.elastic.co).
129139

130-
To connect to Elastic Cloud you just need the `Cloud ID` and the `API key`.
140+
For connecting to Elastic Cloud you just need the `Cloud ID` and the `API key`.
131141

132142
You can get the `Cloud ID` from the `My deployment` page of your dashboard (see the red
133143
rectangle reported in the screenshot).
@@ -150,8 +160,8 @@ After this step you will get the `API key`in the API keys page.
150160
**IMPORTANT**: you need to copy and store the `API key`in a secure place, since you will not
151161
be able to view it again in Elastic Cloud.
152162

153-
Once you have collected the `Cloud ID` and the `API key` you can use the `ClientBuilder` of
154-
`elasticsearch-php` to connect to your Elastic Cloud instance, as follows:
163+
Once you have collected the `Cloud ID` and the `API key` you can use `elasticsearch-php`
164+
to connect to your Elastic Cloud instance, as follows:
155165

156166
```php
157167
$client = ClientBuilder::create()

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"license": "MIT",
1212
"require": {
1313
"php": "^7.4 || ^8.0",
14-
"elastic/transport": "=8.x-dev@dev",
14+
"elastic/transport": "^8.0",
1515
"psr/http-client": "^1.0",
1616
"psr/http-message": "^1.0",
1717
"psr/log": "^1|^2|^3",

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
final class Client
2929
{
3030
const CLIENT_NAME = 'es';
31-
const VERSION = '8.0.0-rc2';
31+
const VERSION = '8.0.0';
3232

3333
use ClientEndpointsTrait;
3434
use EndpointTrait;

0 commit comments

Comments
 (0)