Skip to content

Commit

Permalink
Add Elasticsearch 7 client in Elasticsearch 8 compatibility mode
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Apr 12, 2023
1 parent 1693932 commit 11bead3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ jobs:
- php-version: '8.1'
elasticsearch-version: '7.11.1'
elasticsearch-package-constraint: '~7.11.0'
minimum-stability: 'stable'
dependency-versions: 'highest'
tools: 'composer:v2'
php-cs-fixer: false

- php-version: '8.2'
elasticsearch-version: '8.7.0'
elasticsearch-package-constraint: '~7.11.0'
minimum-stability: 'stable'
dependency-versions: 'highest'
tools: 'composer:v2'
php-cs-fixer: false

- php-version: '8.2'
elasticsearch-version: '8.7.0'
elasticsearch-package-constraint: '~7.11.0'
minimum-stability: 'dev'
dependency-versions: 'highest'
tools: 'composer:v2'
Expand Down Expand Up @@ -117,5 +133,4 @@ jobs:
run: vendor/bin/behat --suite=zend_lucene

- name: Execute elastic behat tests
if: ${{ matrix.php-version < '8.0' }} # requires fixing elastic tests on 7.11 (sorting)
run: vendor/bin/behat --suite=elastic
11 changes: 11 additions & 0 deletions Search/Adapter/ElasticSearchAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Search/ObjectToDocumentConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private function populateDocument(
$type = $mapping['type'];
/** @var FieldInterface $mappingField */
$mappingField = $mapping['field'];
$condition = method_exists($mappingField, 'getCondition') ? $mappingField->getCondition() : null;
$condition = \method_exists($mappingField, 'getCondition') ? $mappingField->getCondition() : null;
$validField = $condition ? $this->fieldEvaluator->evaluateCondition($object, $condition) : true;

if (false === $validField) {
Expand Down

0 comments on commit 11bead3

Please sign in to comment.