Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Fix a regression from 78b9728
Browse files Browse the repository at this point in the history
Fixes "undefined index type" during normal bulk indexing operations. Fixes #138.
  • Loading branch information
Sam Stenvall committed Dec 18, 2019
1 parent 4f46cea commit 9cd2260
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/Documents/Bulk/BulkResponseAggregator.php
@@ -1,5 +1,7 @@
<?php namespace Nord\Lumen\Elasticsearch\Documents\Bulk;

use Illuminate\Support\Arr;

class BulkResponseAggregator
{

Expand Down Expand Up @@ -54,10 +56,10 @@ protected function parseErrors(array $response): void
$items = $response['items'] ?? [];

foreach ($items as $item) {
$item = $item['type'];
$operation = Arr::first($item);

// Ignore items without errors
$error = $item['error'] ?? null;
$error = $operation['error'] ?? null;

if ($error === null) {
continue;
Expand All @@ -71,8 +73,8 @@ protected function parseErrors(array $response): void
}

$this->errors[] = sprintf('Error "%s" reason "%s". Cause "%s" reason "%s". Index "%s", type "%s", id "%s"',
$error['type'], $error['reason'], $causedBy['type'], $causedBy['reason'], $item['_index'],
$item['_type'], $item['_id']);
$error['type'], $error['reason'], $causedBy['type'], $causedBy['reason'], $operation['_index'],
$operation['_type'], $operation['_id']);
}
}
}
12 changes: 6 additions & 6 deletions tests/Documents/Bulk/BulkResponseAggregatorTest.php
Expand Up @@ -36,9 +36,9 @@ public function testAddResponse()

$response = [
'items' => [
// An item with an error
// An index operation with an error
[
'type' => [
'index' => [
'_index' => 'foo',
'_type' => 'bar',
'_id' => 'baz',
Expand All @@ -52,17 +52,17 @@ public function testAddResponse()
],
],
],
// An item without an error
// An delete operation without an error
[
'type' => [
'delete' => [
'_index' => 'foo',
'_type' => 'bar',
'_id' => 'baz',
],
],
// An item with an error, but no caused_by
// An create operation with an error, but no caused_by
[
'type' => [
'create' => [
'_index' => 'foo',
'_type' => 'bar',
'_id' => 'baz',
Expand Down

0 comments on commit 9cd2260

Please sign in to comment.