def terms_iterator_for_elasticsearch(fo: IO, index_name: str):
species_list = config["<STR_LIT>"].get("<STR_LIT>", [])<EOL>fo.seek(<NUM_LIT:0>)  <EOL>with gzip.open(fo, "<STR_LIT>") as f:<EOL><INDENT>for line in f:<EOL><INDENT>term = json.loads(line)<EOL>if "<STR_LIT>" not in term:<EOL><INDENT>continue<EOL><DEDENT>term = term["<STR_LIT>"]<EOL>species_id = term.get("<STR_LIT>", None)<EOL>if species_list and species_id and species_id not in species_list:<EOL><INDENT>continue<EOL><DEDENT>all_term_ids = set()<EOL>for term_id in [term["<STR_LIT:id>"]] + term.get("<STR_LIT>", []):<EOL><INDENT>all_term_ids.add(term_id)<EOL>all_term_ids.add(lowercase_term_id(term_id))<EOL><DEDENT>term["<STR_LIT>"] = copy.copy(list(all_term_ids))<EOL>yield {<EOL>"<STR_LIT>": "<STR_LIT:index>",<EOL>"<STR_LIT>": index_name,<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": term["<STR_LIT:id>"],<EOL>"<STR_LIT>": copy.deepcopy(term),<EOL>}<EOL><DEDENT><DEDENT>
Add index_name to term documents for bulk load