Skip to content

Commit 0b0137c

Browse files
committed
[BUGFIX] After changing NodeType, ES indexes contains two documents
In ES the ID property is unique inside a single document type. With the current implementation, after a NodeType change, we create a new document with the new NodeType, but the old one stay in the index. This change solve the issue with a DELETE query to check is an other document share the same _id before indexing new values.
1 parent 469fb34 commit 0b0137c

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

  • Classes/Flowpack/ElasticSearch/ContentRepositoryAdaptor/Indexer

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,24 @@ public function indexNode(NodeInterface $node, $targetWorkspaceName = NULL) {
129129

130130
$mappingType = $this->getIndex()->findType(NodeTypeMappingBuilder::convertNodeTypeNameToMappingName($nodeType));
131131

132+
// Remove document with the same contextPathHash but different NodeType, required after NodeType change
133+
$this->getIndex()->request('DELETE', '/_query', array(), json_encode([
134+
'query' => [
135+
'bool' => [
136+
'must' => [
137+
'ids' => [
138+
'values' => [ $contextPathHash ]
139+
]
140+
],
141+
'must_not' => [
142+
'term' => [
143+
'_type' => str_replace('.', '/', $node->getNodeType()->getName())
144+
]
145+
],
146+
]
147+
]
148+
]));
149+
132150
if ($node->isRemoved()) {
133151
// TODO: handle deletion from the fulltext index as well
134152
$mappingType->deleteDocumentById($contextPathHash);

0 commit comments

Comments
 (0)