in curator/helpers/utils.py [0:0]
def multitarget_match(pattern: str, index_list: list) -> list:
"""
Convert Elasticsearch multi-target syntax ``pattern`` into Python regex
patterns. Match against ``index_list`` and return the list of matches while
excluding any negative matches.
:param pattern: The Elasticsearch multi-target syntax pattern
:param index_list: The list of indices to match against
:type pattern: str
:type index_list: list
:returns: The final resulting list of indices
:rtype: list
"""
retval = []
excluded = []
includes = []
excludes = []
logger.debug('Multi-target syntax pattern: %s', pattern)
elements = multitarget_fix(pattern).split(',')
logger.debug('Individual elements of pattern: %s', elements)
for element in elements:
# Exclude elements are prefixed with '-'
exclude = element.startswith('-')
# Any index prepended with a . is probably a hidden index, but
# we need to escape the . for regex to treat it as a literal
matchstr = element.replace('.', '\\.')
# Replace Elasticsearch wildcard * with .* for Python regex
matchstr = matchstr.replace('*', '.*')
# logger.debug('matchstr: %s', matchstr)
# If it is not an exclude, add the output of regex_loop to `includes`
if not exclude:
includes += regex_loop(matchstr, index_list)
# If it is an exclude pattern, add the output of regex_loop to `excludes`
# Remove the `-` from the matchstr ([1:]) before sending.
if exclude:
excludes += regex_loop(matchstr[1:], index_list)
# Create a unique list of indices to loop through
for idx in list(set(includes)):
# If idx is not in the unique list of excludes, add it to retval
if idx not in list(set(excludes)):
retval.append(idx)
else:
# Otherwise, add it to the excludes
excluded.append(idx)
# Sort the lists alphabetically
retval.sort()
excluded.sort()
# Log the results
logger.debug('Included indices: %s', retval)
logger.debug('Excluded indices: %s', excluded)
return retval