diff --git a/BulkCommand.php b/BulkCommand.php index aa78d78c..86d16b4a 100644 --- a/BulkCommand.php +++ b/BulkCommand.php @@ -72,9 +72,17 @@ public function execute() $body = '{}'; } elseif (is_array($this->actions)) { $body = ''; + $prettyPrintSupported = property_exists('yii\\helpers\\Json', 'prettyPrint'); + if ($prettyPrintSupported) { + $originalPrettyPrint = Json::$prettyPrint; + Json::$prettyPrint = false; // ElasticSearch bulk API uses new lines as delimiters. + } foreach ($this->actions as $action) { $body .= Json::encode($action) . "\n"; } + if ($prettyPrintSupported) { + Json::$prettyPrint = $originalPrettyPrint; + } } else { $body = $this->actions; } diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e78001d..e390a862 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Yii Framework 2 Elasticsearch extension Change Log 2.1.5 under development ----------------------- -- no changes in this release. +- Bug #344: Disabled JSON pretty print for ElasticSearch bulk API (rhertogh) 2.1.4 May 22, 2023