From 0652ccdc454cac554751ef32c69f8bdc345fa7a8 Mon Sep 17 00:00:00 2001 From: Identei <> Date: Fri, 7 Oct 2022 16:59:24 -0600 Subject: [PATCH] Add an option to set the op_type for the ElasticsearchHandler --- src/Monolog/Handler/ElasticsearchHandler.php | 3 ++- tests/Monolog/Handler/ElasticsearchHandlerTest.php | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Monolog/Handler/ElasticsearchHandler.php b/src/Monolog/Handler/ElasticsearchHandler.php index c288824aa..89594cd8f 100644 --- a/src/Monolog/Handler/ElasticsearchHandler.php +++ b/src/Monolog/Handler/ElasticsearchHandler.php @@ -85,6 +85,7 @@ public function __construct(Client|Client8 $client, array $options = [], int|str 'index' => 'monolog', // Elastic index name 'type' => '_doc', // Elastic document type 'ignore_error' => false, // Suppress Elasticsearch exceptions + 'op_type' => 'index', // Elastic op_type (index or create) (https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#docs-index-api-op_type) ], $options ); @@ -162,7 +163,7 @@ protected function bulkSend(array $records): void foreach ($records as $record) { $params['body'][] = [ - 'index' => $this->needsType ? [ + $this->options['op_type'] => $this->needsType ? [ '_index' => $record['_index'], '_type' => $record['_type'], ] : [ diff --git a/tests/Monolog/Handler/ElasticsearchHandlerTest.php b/tests/Monolog/Handler/ElasticsearchHandlerTest.php index e8e466dfa..37300e5a8 100644 --- a/tests/Monolog/Handler/ElasticsearchHandlerTest.php +++ b/tests/Monolog/Handler/ElasticsearchHandlerTest.php @@ -33,6 +33,7 @@ class ElasticsearchHandlerTest extends TestCase protected array $options = [ 'index' => 'my_index', 'type' => 'doc_type', + 'op_type' => 'index', ]; public function setUp(): void @@ -93,6 +94,7 @@ public function testOptions() 'index' => $this->options['index'], 'type' => $this->options['type'], 'ignore_error' => false, + 'op_type' => $this->options['op_type'], ]; if ($this->client instanceof Client8 || $this->client::VERSION[0] === '7') {