Skip to content

Commit f729753

Browse files
committed
Merge pull request #20 from Flowpack/fix-error-detection
[TASK] Fix false positives with bulk request error detection
2 parents 6397454 + 4eb16d8 commit f729753

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

  • Classes/Flowpack/ElasticSearch/ContentRepositoryAdaptor/Indexer

Classes/Flowpack/ElasticSearch/ContentRepositoryAdaptor/Indexer/NodeIndexer.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,15 @@ public function getIndex() {
167167
* @return void
168168
*/
169169
public function indexNode(Node $node) {
170-
$identifier = sha1($node->getContextPath());
170+
$contextPathHash = sha1($node->getContextPath());
171171
$nodeType = $node->getNodeType();
172172

173173
$mappingType = $this->getIndex()->findType(NodeTypeMappingBuilder::convertNodeTypeNameToMappingName($nodeType));
174174

175175
if ($node->isRemoved()) {
176176
// TODO: handle deletion from the fulltext index as well
177-
$mappingType->deleteDocumentById($identifier);
178-
$this->logger->log(sprintf('NodeIndexer: Removed node %s from index (node flagged as removed). Persistence ID: %s', $node->getContextPath(), $identifier), LOG_DEBUG, NULL, 'ElasticSearch (CR)');
177+
$mappingType->deleteDocumentById($contextPathHash);
178+
$this->logger->log(sprintf('NodeIndexer: Removed node %s from index (node flagged as removed). ID: %s', $node->getContextPath(), $contextPathHash), LOG_DEBUG, NULL, 'ElasticSearch (CR)');
179179

180180
return;
181181
}
@@ -189,15 +189,15 @@ public function indexNode(Node $node) {
189189
// Property Indexing
190190
if (isset($propertyConfiguration['elasticSearch']) && isset($propertyConfiguration['elasticSearch']['indexing'])) {
191191
if ($propertyConfiguration['elasticSearch']['indexing'] !== '') {
192-
$nodePropertiesToBeStoredInElasticSearchIndex[$propertyName] = $this->evaluateEelExpression($propertyConfiguration['elasticSearch']['indexing'], $node, $propertyName, ($node->hasProperty($propertyName) ? $node->getProperty($propertyName) : NULL), $identifier);
192+
$nodePropertiesToBeStoredInElasticSearchIndex[$propertyName] = $this->evaluateEelExpression($propertyConfiguration['elasticSearch']['indexing'], $node, $propertyName, ($node->hasProperty($propertyName) ? $node->getProperty($propertyName) : NULL), $contextPathHash);
193193
}
194194
} elseif (isset($propertyConfiguration['type']) && isset($this->defaultConfigurationPerType[$propertyConfiguration['type']]['indexing'])) {
195195

196196
if ($this->defaultConfigurationPerType[$propertyConfiguration['type']]['indexing'] !== '') {
197-
$nodePropertiesToBeStoredInElasticSearchIndex[$propertyName] = $this->evaluateEelExpression($this->defaultConfigurationPerType[$propertyConfiguration['type']]['indexing'], $node, $propertyName, ($node->hasProperty($propertyName) ? $node->getProperty($propertyName) : NULL), $identifier);
197+
$nodePropertiesToBeStoredInElasticSearchIndex[$propertyName] = $this->evaluateEelExpression($this->defaultConfigurationPerType[$propertyConfiguration['type']]['indexing'], $node, $propertyName, ($node->hasProperty($propertyName) ? $node->getProperty($propertyName) : NULL), $contextPathHash);
198198
}
199199
} else {
200-
$this->logger->log(sprintf('NodeIndexer (%s) - Property "%s" not indexed because no configuration found.', $identifier, $propertyName), LOG_DEBUG, NULL, 'ElasticSearch (CR)');
200+
$this->logger->log(sprintf('NodeIndexer (%s) - Property "%s" not indexed because no configuration found.', $contextPathHash, $propertyName), LOG_DEBUG, NULL, 'ElasticSearch (CR)');
201201
}
202202

203203
if ($fulltextIndexingEnabledForNode === TRUE) {
@@ -225,7 +225,7 @@ public function indexNode(Node $node) {
225225

226226
$document = new ElasticSearchDocument($mappingType,
227227
$nodePropertiesToBeStoredInElasticSearchIndex,
228-
$identifier
228+
$contextPathHash
229229
);
230230

231231
$documentData = $document->getData();
@@ -273,7 +273,7 @@ public function indexNode(Node $node) {
273273
$this->updateFulltext($node, $fulltextIndexOfNode);
274274
}
275275

276-
$this->logger->log(sprintf('NodeIndexer: Added / updated node %s. Persistence ID: %s', $node->getContextPath(), $identifier), LOG_DEBUG, NULL, 'ElasticSearch (CR)');
276+
$this->logger->log(sprintf('NodeIndexer: Added / updated node %s. ID: %s', $node->getContextPath(), $contextPathHash), LOG_DEBUG, NULL, 'ElasticSearch (CR)');
277277
}
278278

279279
/**
@@ -423,7 +423,8 @@ public function flush() {
423423
if ($content !== '') {
424424
$responseAsLines = $this->getIndex()->request('POST', '/_bulk', array(), $content)->getOriginalResponse()->getContent();
425425
foreach (explode('\n', $responseAsLines) as $responseLine) {
426-
if (strpos($responseLine, 'error') !== FALSE) {
426+
$response = json_decode($responseLine);
427+
if ($response->errors !== FALSE) {
427428
$this->logger->log('Indexing Error: ' . $responseLine, LOG_ERR);
428429
}
429430
}
@@ -527,6 +528,9 @@ public function updateIndexAlias() {
527528
}
528529
} catch (\Flowpack\ElasticSearch\Transfer\Exception\ApiException $exception) {
529530
// in case of 404, do not throw an error...
531+
if ($exception->getResponse()->getStatusCode() !== 404) {
532+
throw $exception;
533+
}
530534
}
531535

532536
$aliasActions[] = array(

0 commit comments

Comments
 (0)