def merge_subsets(a, b):
    'Merges field subset definitions together. The b subset is merged into the a subset. Assumes that subsets have been stripped of non-ecs options.'
    for key in b:
        if (key not in a):
            a[key] = b[key]
        elif (('fields' in a[key]) and ('fields' in b[key])):
            if (b[key]['fields'] == '*'):
                a[key]['fields'] = '*'
            elif (isinstance(a[key]['fields'], dict) and isinstance(b[key]['fields'], dict)):
                merge_subsets(a[key]['fields'], b[key]['fields'])
        elif (('fields' in a[key]) or ('fields' in b[key])):
            raise ValueError("Subsets unmergeable: 'fields' found in key '{}' in only one subset".format(key))
        if (a[key].get('enabled', True) or b[key].get('enabled', True)):
            a[key].pop('enabled', None)
        if (a[key].get('index', True) or b[key].get('index', True)):
            a[key].pop('index', None)
Merges field subset definitions together. The b subset is merged into the a subset. Assumes that subsets have been stripped of non-ecs options.
def merge_subsets(a, b):
    
    for key in b:
        if (key not in a):
            a[key] = b[key]
        elif (('fields' in a[key]) and ('fields' in b[key])):
            if (b[key]['fields'] == '*'):
                a[key]['fields'] = '*'
            elif (isinstance(a[key]['fields'], dict) and isinstance(b[key]['fields'], dict)):
                merge_subsets(a[key]['fields'], b[key]['fields'])
        elif (('fields' in a[key]) or ('fields' in b[key])):
            raise ValueError("Subsets unmergeable: 'fields' found in key '{}' in only one subset".format(key))
        if (a[key].get('enabled', True) or b[key].get('enabled', True)):
            a[key].pop('enabled', None)
        if (a[key].get('index', True) or b[key].get('index', True)):
            a[key].pop('index', None)