Skip to content

Commit

Permalink
Up to elasticsearch 8 (#2181)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pawelkeska authored Jan 17, 2024
1 parent 0f6b04b commit ad5452a
Show file tree
Hide file tree
Showing 92 changed files with 1,592 additions and 4,151 deletions.
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
"require": {
"php": "~8.0.0 || ~8.1.0 || ~8.2.0",
"ext-json": "*",
"elasticsearch/elasticsearch": "^7.10",
"elastic/transport": "^8.8",
"elasticsearch/elasticsearch": "^8.11",
"guzzlehttp/psr7": "^2.0",
"nyholm/dsn": "^2.0.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"symfony/deprecation-contracts": "^3.0"
},
"require-dev": {
"aws/aws-sdk-php": "^3.155",
"guzzlehttp/guzzle": "^7.2",
"phpstan/phpstan": "^1.5",
"phpstan/phpstan-phpunit": "^1.1",
Expand All @@ -45,6 +46,11 @@
"Elastica\\Test\\": "tests/"
}
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
},
"extra": {
"branch-alias": {
"dev-master": "7.0.x-dev"
Expand Down
4 changes: 3 additions & 1 deletion docker/docker-compose.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ version: '3.8'

services:
es01:
image: &image docker.elastic.co/elasticsearch/elasticsearch:${ES_VERSION:-7.15.2}
container_name: es01
image: &image docker.elastic.co/elasticsearch/elasticsearch:${ES_VERSION:-8.11.1}
command: &command >
/bin/sh -c "(./bin/elasticsearch-plugin list | grep -q ingest-attachment || ./bin/elasticsearch-plugin install --batch ingest-attachment) && /usr/local/bin/docker-entrypoint.sh"
environment: &environment
Expand All @@ -28,6 +29,7 @@ services:
networks: &networks
- elastic
es02:
container_name: es02
image: *image
command: *command
environment:
Expand Down
1 change: 1 addition & 0 deletions docker/docker-compose.proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: '3.4'

services:
proxy:
container_name: proxy
image: nginx:1.17-alpine
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
Expand Down
6 changes: 5 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ version: '3.4'

services:
php:
build: php/
container_name: php
build:
dockerfile: php/Dockerfile
volumes:
- ../:/var/www/html
networks:
Expand All @@ -15,6 +17,8 @@ services:
- ES_HOST=es01
- PROXY_HOST=proxy
- ES_VERSION=${ES_VERSION}
stdin_open: true
tty: true

networks:
elastic:
Expand Down
2 changes: 2 additions & 0 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM php:8.1-alpine

WORKDIR /var/www/html

COPY --from=composer /usr/bin/composer /usr/bin/composer

# Install requried packages for running Make and Phive
Expand Down
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ parameters:
count: 1
path: src/QueryBuilder.php

-
message: "#^Function GuzzleHttp\\\\Psr7\\\\modify_request not found\\.$#"
count: 1
path: src/Transport/AwsAuthV4.php

-
message: "#^Function GuzzleHttp\\\\Psr7\\\\stream_for not found\\.$#"
count: 1
path: src/Transport/Guzzle.php

-
message: "#^Parameter \\#1 \\$precision of method Elastica\\\\Aggregation\\\\GeohashGrid\\:\\:setPrecision\\(\\) expects int\\|string, float given\\.$#"
count: 1
Expand Down Expand Up @@ -180,11 +170,6 @@ parameters:
count: 1
path: tests/SearchTest.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: tests/SnapshotTest.php

-
message: "#^Parameter \\#1 \\$suggestion of static method Elastica\\\\Suggest\\:\\:create\\(\\) expects Elastica\\\\Suggest\\|Elastica\\\\Suggest\\\\AbstractSuggest, Elastica\\\\Query\\\\BoolQuery given\\.$#"
count: 1
Expand Down
23 changes: 16 additions & 7 deletions src/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

namespace Elastica;

use Elastic\Elasticsearch\Exception\ClientResponseException;
use Elastic\Elasticsearch\Exception\MissingParameterException;
use Elastic\Elasticsearch\Exception\ServerResponseException;
use Elastic\Transport\Exception\NoNodeAvailableException;
use Elastica\Bulk\Action;
use Elastica\Bulk\Action\AbstractDocument as AbstractDocumentAction;
use Elastica\Bulk\Response as BulkResponse;
use Elastica\Bulk\ResponseSet;
use Elastica\Exception\Bulk\ResponseException as BulkResponseException;
use Elastica\Exception\ClientException;
use Elastica\Exception\ConnectionException;
use Elastica\Exception\InvalidException;
use Elastica\Exception\RequestEntityTooLargeException;
use Elastica\Exception\ResponseException;
use Elastica\Script\AbstractScript;

class Bulk
Expand Down Expand Up @@ -277,15 +279,22 @@ public function toArray(): array
}

/**
* @throws ClientException
* @throws ConnectionException
* @throws ResponseException
* @throws MissingParameterException if a required parameter is missing
* @throws NoNodeAvailableException if all the hosts are offline
* @throws ClientResponseException if the status code of response is 4xx
* @throws ServerResponseException if the status code of response is 5xx
* @throws BulkResponseException
* @throws InvalidException
* @throws ClientException
*/
public function send(): ResponseSet
{
$response = $this->_client->request($this->getPath(), Request::POST, (string) $this, $this->_requestParams, Request::NDJSON_CONTENT_TYPE);
$params = ['body' => (string) $this];

if ($this->hasIndex()) {
$params['index'] = $this->getIndex();
}

$response = $this->_client->baseBulk(\array_merge($params, $this->_requestParams));

return $this->_processResponse($response);
}
Expand Down
3 changes: 0 additions & 3 deletions src/Bulk/ResponseSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public function __construct(BaseResponse $response, array $bulkResponses)
{
parent::__construct($response->getData(), $response->getStatus());

$this->setQueryTime($response->getQueryTime());
$this->setTransferInfo($response->getTransferInfo());

$this->_bulkResponses = $bulkResponses;
}

Expand Down
Loading

0 comments on commit ad5452a

Please sign in to comment.