Skip to content

Commit ad5452a

Browse files
authored
Up to elasticsearch 8 (#2181)
This is a major (breaking) change to Elastica to make it compatible with Elasticsearch 8.0. More work and details will follow tracked in #2185 The goal of this PR is to get it to an alpha version.
1 parent 0f6b04b commit ad5452a

File tree

92 files changed

+1592
-4151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1592
-4151
lines changed

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
"require": {
1818
"php": "~8.0.0 || ~8.1.0 || ~8.2.0",
1919
"ext-json": "*",
20-
"elasticsearch/elasticsearch": "^7.10",
20+
"elastic/transport": "^8.8",
21+
"elasticsearch/elasticsearch": "^8.11",
22+
"guzzlehttp/psr7": "^2.0",
2123
"nyholm/dsn": "^2.0.0",
2224
"psr/log": "^1.0 || ^2.0 || ^3.0",
2325
"symfony/deprecation-contracts": "^3.0"
2426
},
2527
"require-dev": {
26-
"aws/aws-sdk-php": "^3.155",
2728
"guzzlehttp/guzzle": "^7.2",
2829
"phpstan/phpstan": "^1.5",
2930
"phpstan/phpstan-phpunit": "^1.1",
@@ -45,6 +46,11 @@
4546
"Elastica\\Test\\": "tests/"
4647
}
4748
},
49+
"config": {
50+
"allow-plugins": {
51+
"php-http/discovery": true
52+
}
53+
},
4854
"extra": {
4955
"branch-alias": {
5056
"dev-master": "7.0.x-dev"

docker/docker-compose.es.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ version: '3.8'
22

33
services:
44
es01:
5-
image: &image docker.elastic.co/elasticsearch/elasticsearch:${ES_VERSION:-7.15.2}
5+
container_name: es01
6+
image: &image docker.elastic.co/elasticsearch/elasticsearch:${ES_VERSION:-8.11.1}
67
command: &command >
78
/bin/sh -c "(./bin/elasticsearch-plugin list | grep -q ingest-attachment || ./bin/elasticsearch-plugin install --batch ingest-attachment) && /usr/local/bin/docker-entrypoint.sh"
89
environment: &environment
@@ -28,6 +29,7 @@ services:
2829
networks: &networks
2930
- elastic
3031
es02:
32+
container_name: es02
3133
image: *image
3234
command: *command
3335
environment:

docker/docker-compose.proxy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ version: '3.4'
22

33
services:
44
proxy:
5+
container_name: proxy
56
image: nginx:1.17-alpine
67
volumes:
78
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro

docker/docker-compose.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ version: '3.4'
66

77
services:
88
php:
9-
build: php/
9+
container_name: php
10+
build:
11+
dockerfile: php/Dockerfile
1012
volumes:
1113
- ../:/var/www/html
1214
networks:
@@ -15,6 +17,8 @@ services:
1517
- ES_HOST=es01
1618
- PROXY_HOST=proxy
1719
- ES_VERSION=${ES_VERSION}
20+
stdin_open: true
21+
tty: true
1822

1923
networks:
2024
elastic:

docker/php/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM php:8.1-alpine
22

3+
WORKDIR /var/www/html
4+
35
COPY --from=composer /usr/bin/composer /usr/bin/composer
46

57
# Install requried packages for running Make and Phive

phpstan-baseline.neon

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ parameters:
2020
count: 1
2121
path: src/QueryBuilder.php
2222

23-
-
24-
message: "#^Function GuzzleHttp\\\\Psr7\\\\modify_request not found\\.$#"
25-
count: 1
26-
path: src/Transport/AwsAuthV4.php
27-
28-
-
29-
message: "#^Function GuzzleHttp\\\\Psr7\\\\stream_for not found\\.$#"
30-
count: 1
31-
path: src/Transport/Guzzle.php
32-
3323
-
3424
message: "#^Parameter \\#1 \\$precision of method Elastica\\\\Aggregation\\\\GeohashGrid\\:\\:setPrecision\\(\\) expects int\\|string, float given\\.$#"
3525
count: 1
@@ -180,11 +170,6 @@ parameters:
180170
count: 1
181171
path: tests/SearchTest.php
182172

183-
-
184-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
185-
count: 1
186-
path: tests/SnapshotTest.php
187-
188173
-
189174
message: "#^Parameter \\#1 \\$suggestion of static method Elastica\\\\Suggest\\:\\:create\\(\\) expects Elastica\\\\Suggest\\|Elastica\\\\Suggest\\\\AbstractSuggest, Elastica\\\\Query\\\\BoolQuery given\\.$#"
190175
count: 1

src/Bulk.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
namespace Elastica;
44

5+
use Elastic\Elasticsearch\Exception\ClientResponseException;
6+
use Elastic\Elasticsearch\Exception\MissingParameterException;
7+
use Elastic\Elasticsearch\Exception\ServerResponseException;
8+
use Elastic\Transport\Exception\NoNodeAvailableException;
59
use Elastica\Bulk\Action;
610
use Elastica\Bulk\Action\AbstractDocument as AbstractDocumentAction;
711
use Elastica\Bulk\Response as BulkResponse;
812
use Elastica\Bulk\ResponseSet;
913
use Elastica\Exception\Bulk\ResponseException as BulkResponseException;
1014
use Elastica\Exception\ClientException;
11-
use Elastica\Exception\ConnectionException;
1215
use Elastica\Exception\InvalidException;
1316
use Elastica\Exception\RequestEntityTooLargeException;
14-
use Elastica\Exception\ResponseException;
1517
use Elastica\Script\AbstractScript;
1618

1719
class Bulk
@@ -277,15 +279,22 @@ public function toArray(): array
277279
}
278280

279281
/**
280-
* @throws ClientException
281-
* @throws ConnectionException
282-
* @throws ResponseException
282+
* @throws MissingParameterException if a required parameter is missing
283+
* @throws NoNodeAvailableException if all the hosts are offline
284+
* @throws ClientResponseException if the status code of response is 4xx
285+
* @throws ServerResponseException if the status code of response is 5xx
283286
* @throws BulkResponseException
284-
* @throws InvalidException
287+
* @throws ClientException
285288
*/
286289
public function send(): ResponseSet
287290
{
288-
$response = $this->_client->request($this->getPath(), Request::POST, (string) $this, $this->_requestParams, Request::NDJSON_CONTENT_TYPE);
291+
$params = ['body' => (string) $this];
292+
293+
if ($this->hasIndex()) {
294+
$params['index'] = $this->getIndex();
295+
}
296+
297+
$response = $this->_client->baseBulk(\array_merge($params, $this->_requestParams));
289298

290299
return $this->_processResponse($response);
291300
}

src/Bulk/ResponseSet.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ public function __construct(BaseResponse $response, array $bulkResponses)
2323
{
2424
parent::__construct($response->getData(), $response->getStatus());
2525

26-
$this->setQueryTime($response->getQueryTime());
27-
$this->setTransferInfo($response->getTransferInfo());
28-
2926
$this->_bulkResponses = $bulkResponses;
3027
}
3128

0 commit comments

Comments
 (0)