Skip to content

Commit 136fa0f

Browse files
committed
Disable JSON pretty print for ElasticSearch bulk API since it uses new lines as delimiter
1 parent 70baa03 commit 136fa0f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
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+
$prettyPrintSupport = property_exists('yii\\helpers\\Json', 'prettyPrint');
76+
if ($prettyPrintSupport) {
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 ($prettyPrintSupport) {
84+
Json::$prettyPrint = $originalPrettyPrint;
85+
}
7886
} else {
7987
$body = $this->actions;
8088
}

0 commit comments

Comments
 (0)