public void copyFields(Document source, Document target, FieldSet fieldSet) {
        if (fieldSet instanceof DocumentOnly) {
            var actual = source.getDataType().fieldSet(DocumentOnly.NAME);
            if (actual != null) {
                for (Iterator<Map.Entry<Field, FieldValue>> i = source.iterator(); i.hasNext();) {
                    Map.Entry<Field, FieldValue> v = i.next();
                    if (actual.contains(v.getKey())) {
                        target.setFieldValue(v.getKey(), v.getValue());
                    }
                }
                return;
            }
        }
        for (Iterator<Map.Entry<Field, FieldValue>> i = source.iterator(); i.hasNext();) {
            Map.Entry<Field, FieldValue> v = i.next();

            if (fieldSet.contains(v.getKey())) {
                target.setFieldValue(v.getKey(), v.getValue());
            }
        }
    }
Copies fields from one document to another based on whether the fields match the given
fieldset.
document/src/main/java/com/yahoo/document/fieldset/FieldSetRepo.java