From d95a5dd3a62e6d5a4521ba45a85c4a63cf6374b8 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Thu, 13 Apr 2023 01:30:28 +0200 Subject: [PATCH 1/4] Add Elasticsearch 7 client in Elasticsearch 8 compatibility mode --- .github/workflows/test-application.yaml | 9 +++++++++ Search/Adapter/ElasticSearchAdapter.php | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 7d4782f..d589300 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -61,6 +61,14 @@ jobs: tools: 'composer:v2' php-cs-fixer: false + - php-version: '8.5' + elasticsearch-version: '8.14.3' + elasticsearch-package-constraint: '~7.17.0' + minimum-stability: 'dev' + dependency-versions: 'highest' + tools: 'composer:v2' + php-cs-fixer: false + services: elasticsearch: image: elasticsearch:${{ matrix.elasticsearch-version }} @@ -91,6 +99,7 @@ jobs: uses: ramsey/composer-install@v1 with: dependency-versions: ${{matrix.dependency-versions}} + composer-versions: ${{matrix.composer-options}} - name: Run php-cs-fixer if: ${{ matrix.php-cs-fixer }} diff --git a/Search/Adapter/ElasticSearchAdapter.php b/Search/Adapter/ElasticSearchAdapter.php index cd7928f..fff6192 100644 --- a/Search/Adapter/ElasticSearchAdapter.php +++ b/Search/Adapter/ElasticSearchAdapter.php @@ -85,6 +85,17 @@ public function __construct(Factory $factory, ElasticSearchClient $client, $vers $this->client = $client; $this->version = $version; $this->refresh = $refresh; + + if (\version_compare($this->version, '7.11.0', '>=')) { + $client->setConnectionParams([ + 'client' => [ + 'headers' => [ + 'Accept' => ['application/vnd.elasticsearch+json;compatible-with=7'], + 'Content-Type' => ['application/vnd.elasticsearch+json;compatible-with=7'], + ], + ], + ]); + } } public function index(Document $document, $indexName) From 4bd0e0f1e6e9fff8cd1d488ef9bebc3d41a39d8b Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Thu, 18 Jul 2024 13:55:41 +0200 Subject: [PATCH 2/4] Add range of supported client versiong --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a219f5b..8c1cce3 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,8 @@ "conflict": { "guzzlehttp/ringphp": "< 1.0.7", "symfony/security-guard": "5.4.0-BETA1", - "doctrine/doctrine-cache-bundle": "<1.3.1" + "doctrine/doctrine-cache-bundle": "<1.3.1", + "elasticsearch/elasticsearch": "<2.0 || >=8.0" }, "autoload": { "psr-4": { From b21936b02a8159fa989f76ff6efac99bf4655a83 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 11 Feb 2026 17:24:55 +0100 Subject: [PATCH 3/4] Update ci --- .github/workflows/test-application.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index d589300..a80dfdd 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -99,7 +99,6 @@ jobs: uses: ramsey/composer-install@v1 with: dependency-versions: ${{matrix.dependency-versions}} - composer-versions: ${{matrix.composer-options}} - name: Run php-cs-fixer if: ${{ matrix.php-cs-fixer }} From bb546c80eb3ddbb8b52e8740d0b343aa626f56d4 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Wed, 11 Feb 2026 17:48:29 +0100 Subject: [PATCH 4/4] Support ES8 in compatibility mode --- Resources/config/adapter_elastic.xml | 1 + Search/Adapter/Elastic/ClientFactory.php | 18 +++++++++++++++++- Search/Adapter/ElasticSearchAdapter.php | 11 ----------- Tests/docker/docker-elasticsearch-8-19.yml | 19 +++++++++++++++++++ 4 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 Tests/docker/docker-elasticsearch-8-19.yml diff --git a/Resources/config/adapter_elastic.xml b/Resources/config/adapter_elastic.xml index 87e6a3d..43cab08 100644 --- a/Resources/config/adapter_elastic.xml +++ b/Resources/config/adapter_elastic.xml @@ -15,6 +15,7 @@ %massive_search.adapter.elastic.hosts% + %massive_search.adapter.elastic.version% diff --git a/Search/Adapter/Elastic/ClientFactory.php b/Search/Adapter/Elastic/ClientFactory.php index b1c31ce..244ceb0 100644 --- a/Search/Adapter/Elastic/ClientFactory.php +++ b/Search/Adapter/Elastic/ClientFactory.php @@ -28,6 +28,22 @@ class ClientFactory */ public static function create($config) { - return ClientBuilder::create()->setHosts($config['hosts'])->build(); + $clientBuilder = ClientBuilder::create()->setHosts($config['hosts']); + + $elasticSearchVersion = defined(Client::class . '::VERSION') ? Client::VERSION : '5.0'; + $version = $config['version'] ?? $elasticSearchVersion; + + if (\version_compare($version, '7.11.0', '>=')) { + $clientBuilder->setConnectionParams([ + 'client' => [ + 'headers' => [ + 'Accept' => ['application/vnd.elasticsearch+json;compatible-with=7'], + 'Content-Type' => ['application/vnd.elasticsearch+json;compatible-with=7'], + ], + ], + ]); + } + + return $clientBuilder->build(); } } diff --git a/Search/Adapter/ElasticSearchAdapter.php b/Search/Adapter/ElasticSearchAdapter.php index fff6192..cd7928f 100644 --- a/Search/Adapter/ElasticSearchAdapter.php +++ b/Search/Adapter/ElasticSearchAdapter.php @@ -85,17 +85,6 @@ public function __construct(Factory $factory, ElasticSearchClient $client, $vers $this->client = $client; $this->version = $version; $this->refresh = $refresh; - - if (\version_compare($this->version, '7.11.0', '>=')) { - $client->setConnectionParams([ - 'client' => [ - 'headers' => [ - 'Accept' => ['application/vnd.elasticsearch+json;compatible-with=7'], - 'Content-Type' => ['application/vnd.elasticsearch+json;compatible-with=7'], - ], - ], - ]); - } } public function index(Document $document, $indexName) diff --git a/Tests/docker/docker-elasticsearch-8-19.yml b/Tests/docker/docker-elasticsearch-8-19.yml new file mode 100644 index 0000000..0ae7c17 --- /dev/null +++ b/Tests/docker/docker-elasticsearch-8-19.yml @@ -0,0 +1,19 @@ +services: + elasticsearch: + image: docker.elastic.co/elasticsearch/elasticsearch:8.19.0 + environment: + discovery.type: single-node + xpack.security.enabled: 'false' + cluster.routing.allocation.disk.threshold_enabled: 'false' + ports: + - "9200:9200" + healthcheck: + test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"] + interval: 5s + timeout: 5s + retries: 20 + volumes: + - elasticsearch-data:/usr/share/elasticsearch/data + +volumes: + elasticsearch-data: