Skip to content

Commit a7f8dc0

Browse files
committed
Fix 'hosts' key in Elastic 8 configuration
1 parent f78fcaf commit a7f8dc0

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ private function addElasticsearchSection(ArrayNodeDefinition $handlerNode)
908908
->end()
909909
->children()
910910
->scalarNode('id')->end()
911+
->arrayNode('hosts')->prototype('scalar')->end()->end()
911912
->scalarNode('host')->end()
912913
->scalarNode('port')->defaultValue(9200)->end()
913914
->scalarNode('transport')->defaultValue('Http')->end()
@@ -916,7 +917,7 @@ private function addElasticsearchSection(ArrayNodeDefinition $handlerNode)
916917
->end()
917918
->validate()
918919
->ifTrue(function ($v) {
919-
return !isset($v['id']) && !isset($v['host']);
920+
return !isset($v['id']) && !isset($v['host']) && !isset($v['hosts']);
920921
})
921922
->thenInvalid('What must be set is either the host or the id.')
922923
->end()

src/DependencyInjection/MonologExtension.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
304304
$factory = class_exists('Elastic\Elasticsearch\ClientBuilder') ? 'Elastic\Elasticsearch\ClientBuilder' : 'Elasticsearch\ClientBuilder';
305305
$client->setFactory([$factory, 'fromConfig']);
306306
$clientArguments = [
307-
'hosts' => [$handler['elasticsearch']['host']],
307+
'hosts' => $handler['elasticsearch']['hosts'] ?? [$handler['elasticsearch']['host']],
308308
];
309309

310310
if (isset($handler['elasticsearch']['user'], $handler['elasticsearch']['password'])) {
@@ -313,11 +313,18 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
313313
} else {
314314
$client = new Definition('Elastica\Client');
315315

316-
$clientArguments = [
317-
'host' => $handler['elasticsearch']['host'],
318-
'port' => $handler['elasticsearch']['port'],
319-
'transport' => $handler['elasticsearch']['transport'],
320-
];
316+
if (isset($handler['elasticsearch']['hosts'])) {
317+
$clientArguments = [
318+
'hosts' => $handler['elasticsearch']['hosts'],
319+
'transport' => $handler['elasticsearch']['transport'],
320+
];
321+
} else {
322+
$clientArguments = [
323+
'host' => $handler['elasticsearch']['host'],
324+
'port' => $handler['elasticsearch']['port'],
325+
'transport' => $handler['elasticsearch']['transport'],
326+
];
327+
}
321328

322329
if (isset($handler['elasticsearch']['user'], $handler['elasticsearch']['password'])) {
323330
$clientArguments['headers'] = [

0 commit comments

Comments
 (0)