Skip to content

Commit b15c795

Browse files
Merge pull request #344 from rhertogh/disable_pretty_print_for_bulk
Disable JSON pretty print for ElasticSearch bulk API
2 parents 70baa03 + c715e47 commit b15c795

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

BulkCommand.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,17 @@ public function execute()
7272
$body = '{}';
7373
} elseif (is_array($this->actions)) {
7474
$body = '';
75+
$prettyPrintSupported = property_exists('yii\\helpers\\Json', 'prettyPrint');
76+
if ($prettyPrintSupported) {
77+
$originalPrettyPrint = Json::$prettyPrint;
78+
Json::$prettyPrint = false; // ElasticSearch bulk API uses new lines as delimiters.
79+
}
7580
foreach ($this->actions as $action) {
7681
$body .= Json::encode($action) . "\n";
7782
}
83+
if ($prettyPrintSupported) {
84+
Json::$prettyPrint = $originalPrettyPrint;
85+
}
7886
} else {
7987
$body = $this->actions;
8088
}

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Yii Framework 2 Elasticsearch extension Change Log
44
2.1.5 under development
55
-----------------------
66

7-
- no changes in this release.
7+
- Bug #344: Disabled JSON pretty print for ElasticSearch bulk API (rhertogh)
88

99

1010
2.1.4 May 22, 2023

0 commit comments

Comments
 (0)