From 136fa0f08ddae94dbdccbc35e3dd13c3532c9dd6 Mon Sep 17 00:00:00 2001 From: rhertogh Date: Mon, 10 Jul 2023 14:41:59 +0200 Subject: [PATCH 1/2] Disable JSON pretty print for ElasticSearch bulk API since it uses new lines as delimiter --- BulkCommand.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/BulkCommand.php b/BulkCommand.php index aa78d78c..bb27ea52 100644 --- a/BulkCommand.php +++ b/BulkCommand.php @@ -72,9 +72,17 @@ public function execute() $body = '{}'; } elseif (is_array($this->actions)) { $body = ''; + $prettyPrintSupport = property_exists('yii\\helpers\\Json', 'prettyPrint'); + if ($prettyPrintSupport) { + $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 ($prettyPrintSupport) { + Json::$prettyPrint = $originalPrettyPrint; + } } else { $body = $this->actions; } From c715e4702de8752b93dd4b94013b21c7abf93fb7 Mon Sep 17 00:00:00 2001 From: rhertogh Date: Mon, 10 Jul 2023 16:39:23 +0200 Subject: [PATCH 2/2] Updated changelog for #344 (Disabled JSON pretty print for ElasticSearch bulk API) --- BulkCommand.php | 6 +++--- CHANGELOG.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/BulkCommand.php b/BulkCommand.php index bb27ea52..86d16b4a 100644 --- a/BulkCommand.php +++ b/BulkCommand.php @@ -72,15 +72,15 @@ public function execute() $body = '{}'; } elseif (is_array($this->actions)) { $body = ''; - $prettyPrintSupport = property_exists('yii\\helpers\\Json', 'prettyPrint'); - if ($prettyPrintSupport) { + $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 ($prettyPrintSupport) { + if ($prettyPrintSupported) { Json::$prettyPrint = $originalPrettyPrint; } } else { 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