Skip to content

Commit

Permalink
Merge pull request #344 from rhertogh/disable_pretty_print_for_bulk
Browse files Browse the repository at this point in the history
Disable JSON pretty print for ElasticSearch bulk API
  • Loading branch information
beowulfenator committed Jul 10, 2023
2 parents 70baa03 + c715e47 commit b15c795
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions BulkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b15c795

Please sign in to comment.