Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to set the op_type for the ElasticsearchHandler #1766

Merged
merged 1 commit into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Monolog/Handler/ElasticsearchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down Expand Up @@ -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'],
] : [
Expand Down
2 changes: 2 additions & 0 deletions tests/Monolog/Handler/ElasticsearchHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ElasticsearchHandlerTest extends TestCase
protected array $options = [
'index' => 'my_index',
'type' => 'doc_type',
'op_type' => 'index',
];

public function setUp(): void
Expand Down Expand Up @@ -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') {
Expand Down