Skip to content

Commit a9ec417

Browse files
Merge pull request #335 from daniellienert/task/exchange-scroll-with-delete_by_query
TASK: Exchange scrolling and deleting by simple _delete_by_query
2 parents c7b878a + 2990665 commit a9ec417

1 file changed

Lines changed: 1 addition & 31 deletions

File tree

Classes/Driver/Version5/DocumentDriver.php

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ public function delete(NodeInterface $node, string $identifier): array
5757
*/
5858
public function deleteDuplicateDocumentNotMatchingType(Index $index, string $documentIdentifier, NodeType $nodeType): void
5959
{
60-
$result = $index->request('GET', '/_search?scroll=1m', [], json_encode([
61-
'sort' => ['_doc'],
60+
$result = $index->request('POST', '/_delete_by_query', [], json_encode([
6261
'query' => [
6362
'bool' => [
6463
'must' => [
@@ -74,34 +73,5 @@ public function deleteDuplicateDocumentNotMatchingType(Index $index, string $doc
7473
]
7574
]
7675
]));
77-
$treatedContent = $result->getTreatedContent();
78-
$scrollId = $treatedContent['_scroll_id'];
79-
$mapHitToDeleteRequest = function ($hit) {
80-
return json_encode([
81-
'delete' => [
82-
'_type' => $hit['_type'],
83-
'_id' => $hit['_id']
84-
]
85-
]);
86-
};
87-
$bulkRequest = [];
88-
while (isset($treatedContent['hits']['hits']) && $treatedContent['hits']['hits'] !== []) {
89-
$hits = $treatedContent['hits']['hits'];
90-
$bulkRequest = array_merge($bulkRequest, array_map($mapHitToDeleteRequest, $hits));
91-
$result = $index->request('POST', '/_search/scroll', [], json_encode([
92-
'scroll' => '1m',
93-
'scroll_id' => $scrollId,
94-
]), false);
95-
$treatedContent = $result->getTreatedContent();
96-
}
97-
$this->logger->debug(sprintf('NodeIndexer: Check duplicate nodes for %s (%s), found %d document(s)', $documentIdentifier, $nodeType->getName(), count($bulkRequest)), LogEnvironment::fromMethodName(__METHOD__));
98-
if ($bulkRequest !== []) {
99-
$index->request('POST', '/_bulk', [], implode("\n", $bulkRequest) . "\n");
100-
}
101-
$this->searchClient->request('DELETE', '/_search/scroll', [], json_encode([
102-
'scroll_id' => [
103-
$scrollId
104-
]
105-
]));
10676
}
10777
}

0 commit comments

Comments
 (0)