in src/es_pii_tool/helpers/utils.py [0:0]
def get_field_matches(config: t.Dict, result: t.Dict) -> int:
"""Count docs which have the expected fields
:param config: The config from the YAML file
:param result: The query result dict
:type config: dict
:type result: dict
:returns: The count of docs in ``result`` which have the identified fields
:rtype: int
"""
logger.debug('Extracting doc hit count from result')
doc_count = result['hits']['total']['value']
for element in range(0, result['hits']['total']['value']):
for field in config['fields']:
if len(field.split('.')) > 1:
logger.debug('Dotted field "%s" detected...', field)
fielder = result['hits']['hits'][element]['_source']
for key in field.split('.'):
# This should recursively look for each subkey
if key in fielder:
fielder = fielder[key]
else:
doc_count -= 1
break
elif field not in list(result['hits']['hits'][element]['_source'].keys()):
logger.debug('Fieldname "%s" NOT detected...', field)
doc_count -= 1
else:
logger.debug('Root-level fieldname "%s" detected...', field)
return doc_count