Skip to content

Commit 1f5c3c6

Browse files
Add Elasticsearch 7 client in Elasticsearch 8 compatibility mode
1 parent 1693932 commit 1f5c3c6

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

.github/workflows/test-application.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ jobs:
6464
- php-version: '8.1'
6565
elasticsearch-version: '7.11.1'
6666
elasticsearch-package-constraint: '~7.11.0'
67+
minimum-stability: 'stable'
68+
dependency-versions: 'highest'
69+
tools: 'composer:v2'
70+
php-cs-fixer: false
71+
72+
- php-version: '8.2'
73+
elasticsearch-version: '8.7.0'
74+
elasticsearch-package-constraint: '~7.11.0'
75+
minimum-stability: 'stable'
76+
dependency-versions: 'highest'
77+
tools: 'composer:v2'
78+
php-cs-fixer: false
79+
80+
- php-version: '8.2'
81+
elasticsearch-version: '8.7.0'
82+
elasticsearch-package-constraint: '~7.11.0'
6783
minimum-stability: 'dev'
6884
dependency-versions: 'highest'
6985
tools: 'composer:v2'
@@ -117,5 +133,4 @@ jobs:
117133
run: vendor/bin/behat --suite=zend_lucene
118134

119135
- name: Execute elastic behat tests
120-
if: ${{ matrix.php-version < '8.0' }} # requires fixing elastic tests on 7.11 (sorting)
121136
run: vendor/bin/behat --suite=elastic

Search/Adapter/ElasticSearchAdapter.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ public function __construct(Factory $factory, ElasticSearchClient $client, $vers
7878
$this->factory = $factory;
7979
$this->client = $client;
8080
$this->version = $version;
81+
82+
if (\version_compare($this->version, '7.11.0', '>=')) {
83+
$client->setConnectionParams([
84+
'client' => [
85+
'headers' => [
86+
'Accept' => ['application/vnd.elasticsearch+json;compatible-with=7'],
87+
'Content-Type' => ['application/vnd.elasticsearch+json;compatible-with=7'],
88+
],
89+
],
90+
]);
91+
}
8192
}
8293

8394
public function index(Document $document, $indexName)

Search/ObjectToDocumentConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ private function populateDocument(
181181
$type = $mapping['type'];
182182
/** @var FieldInterface $mappingField */
183183
$mappingField = $mapping['field'];
184-
$condition = method_exists($mappingField, 'getCondition') ? $mappingField->getCondition() : null;
184+
$condition = \method_exists($mappingField, 'getCondition') ? $mappingField->getCondition() : null;
185185
$validField = $condition ? $this->fieldEvaluator->evaluateCondition($object, $condition) : true;
186186

187187
if (false === $validField) {

0 commit comments

Comments
 (0)