From ea670b4a9a8a4a5de20a24bc27a4d83fc1ac2a66 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Thu, 13 Apr 2023 01:30:28 +0200 Subject: [PATCH] Add Elasticsearch 7 client in Elasticsearch 8 compatibility mode --- .github/workflows/test-application.yaml | 11 +++++++++++ Search/Adapter/ElasticSearchAdapter.php | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index d8d89120..96656556 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -84,6 +84,16 @@ jobs: php-cs-fixer: false max-phpunit-version: '8' + - php-version: '8.4' + elasticsearch-version: '8.14.3' + elasticsearch-package-constraint: '~7.17.0' + minimum-stability: 'dev' + dependency-versions: 'highest' + tools: 'composer:v2' + php-cs-fixer: false + max-phpunit-version: '8' + composer-options: '--ignore-platform-reqs' + services: elasticsearch: image: elasticsearch:${{ matrix.elasticsearch-version }} @@ -114,6 +124,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 19daa02e..a04d362b 100644 --- a/Search/Adapter/ElasticSearchAdapter.php +++ b/Search/Adapter/ElasticSearchAdapter.php @@ -78,6 +78,17 @@ public function __construct(Factory $factory, ElasticSearchClient $client, $vers $this->factory = $factory; $this->client = $client; $this->version = $version; + + 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)