/** * Build the new document to just contain keys which have a mapping in the new properties. To clean * out any old fields that we no longer use. * @param array() $result original document retrieved from a search * @param array() $properties mapping properties * @return Document */ public function buildNewDocument($result, $properties) { // Build the new document to just contain keys which have a mapping in the new properties. To clean // out any old fields that we no longer use. $data = Util::cleanUnusedFields($result->getSource(), $properties); // Note that while setting the opType to create might improve performance slightly it can cause // trouble if the scroll returns the same id twice. It can do that if the document is updated // during the scroll process. I'm unclear on if it will always do that, so you still have to // perform the date based catch up after the reindex. return new Document($result->getId(), $data); }
/** * @dataProvider cleanUnusedFieldsProvider */ public function testCleanUnusedFields($data, $properties, $expect) { $result = Util::cleanUnusedFields($data, $properties); $this->assertArrayEquals($result, $expect); }