Commit d204bffe authored by David Mendez's avatar David Mendez

Implement parsing of a single property in source for mapping

parent d9dd45c0
......@@ -24,13 +24,18 @@ def parse_mapping_from_es_response(index_mapping, required_source):
"""
Reads the response of the mapping from ES and produces the mapping to use for the subset index
:param index_mapping: mapping dict obtained from es
:param required_source: source (list of properties) to get from the mapping
:return: the mapping ready to be applied to the subset index
"""
mappings_to_apply = {
'properties': {}
}
for source_property in required_source:
print(f'locating: {source_property}')
for current_property in required_source:
mapping_to_apply = get_mapping_to_apply_in_subset_index(index_mapping, current_property)
mappings_to_apply['properties'][current_property] = mapping_to_apply
print(index_mapping)
return mappings_to_apply
def get_mapping_to_apply_in_subset_index(index_mapping, property_path):
......@@ -44,14 +49,11 @@ def get_mapping_to_apply_in_subset_index(index_mapping, property_path):
is_nested = source_property_config.get('properties') is not None
if not is_nested:
mapping_to_apply = {
'type': source_property_config['type']
}
return mapping_to_apply
mapping_to_apply = {
'properties': {}
}
......
......@@ -22,8 +22,18 @@ class TestMappingsHandling(unittest.TestCase):
with open(sample_mapping_path, 'rt') as sample_mapping_file:
mapping_from_base_index = json.load(sample_mapping_file)
source = ['pref_name']
mappings.parse_mapping_from_es_response(mapping_from_base_index, source)
# FINISH THIS!
mappings_to_apply_got = mappings.parse_mapping_from_es_response(mapping_from_base_index, source)
mappings_to_apply_must_be = {
"properties": {
'pref_name': {
'type': 'keyword'
},
}
}
self.assertEqual(mappings_to_apply_got, mappings_to_apply_must_be,
msg='The mappings were not produced correctly!')
def test_locates_source_config_of_property(self):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment