public Collection<IndexSetFieldType> merge(final Collection<FieldTypeDTO> fromNewerIndex,
                                               final Collection<FieldTypeDTO> fromOlderIndex,
                                               final CustomFieldMappings customFieldMappings,
                                               final IndexFieldTypeProfile profile) {
        Map<String, IndexSetFieldType> result = new HashMap<>();
        if (fromNewerIndex != null) {
            fromNewerIndex.forEach(dto -> result.put(
                            dto.fieldName(),
                            toIndexSetFieldType(dto, INDEX)
                    )
            );
        }
        if (fromOlderIndex != null) {
            fromOlderIndex.forEach(dto -> result.putIfAbsent(
                            dto.fieldName(),
                            toIndexSetFieldType(dto, INDEX)
                    )
            );
        }
        if (profile != null) {
            profile.customFieldMappings().forEach(profileMapping ->
                    result.put(
                            profileMapping.fieldName(),
                            toIndexSetFieldType(profileMapping.toFieldTypeDTO(), PROFILE)
                    )
            );
        }
        if (customFieldMappings != null) {
            customFieldMappings.forEach(customFieldMapping -> {
                        final IndexSetFieldType indexSetFieldTypeFromPrevSources = result.get(customFieldMapping.fieldName());
                        result.put(
                                customFieldMapping.fieldName(),
                                toIndexSetFieldType(
                                        customFieldMapping.toFieldTypeDTO(),
                                        indexSetFieldTypeFromPrevSources != null && indexSetFieldTypeFromPrevSources.origin() == PROFILE
                                                ? OVERRIDDEN_PROFILE : OVERRIDDEN_INDEX
                                )

                        );
                    }
            );
        }

        return result.values();
    }
@Test
    void customMappingsOverrideEverything() {
        final Collection<IndexSetFieldType> merged = toTest.merge(
                List.of(
                        FieldTypeDTO.create("changed_field", "long")
                ),
                List.of(
                        FieldTypeDTO.create("changed_field", "date")
                ),
                new CustomFieldMappings(
                        List.of(new CustomFieldMapping("changed_field", "ip"))
                ),
                new IndexFieldTypeProfile("id", "name", "descr", new CustomFieldMappings(
                        List.of(new CustomFieldMapping("changed_field", "double"))
                ))
        );

        assertThat(merged)
                .isNotNull()
                .hasSize(1)
                .contains(new IndexSetFieldType("changed_field", "ip", FieldTypeOrigin.OVERRIDDEN_PROFILE, false));
    }