# Trouve-KA — mise à jour à chaud des synonymes de recherche # Author: Simon-Pierre Boucher # Contact: contact@spboucher.ai """Applique le dictionnaire BILINGUAL_SYNONYMS courant à l'index live. Les synonymes sont search-time : pas de réindexation nécessaire, mais les analyzers font partie des settings → close/open de l'index (indisponibilité de ~1-2 s, les workers retentent d'eux-mêmes). Usage : python scripts/update-synonyms/update.py """ import asyncio from opensearchpy import AsyncOpenSearch from trouveka.config import get_settings from trouveka.search_core import INDEX_SETTINGS async def main() -> None: s = get_settings() client = AsyncOpenSearch(hosts=[s.search_url], timeout=120) try: # Résoudre l'alias vers l'index concret aliases = await client.indices.get_alias(name=s.search_index) concrete = next(iter(aliases)) analysis = {"analysis": INDEX_SETTINGS["settings"]["analysis"]} print(f"→ fermeture de {concrete}") await client.indices.close(index=concrete) try: await client.indices.put_settings(index=concrete, body=analysis) print("→ analyzers/synonymes mis à jour") finally: await client.indices.open(index=concrete) print(f"→ {concrete} rouvert") await client.cluster.health(index=concrete, wait_for_status="yellow", timeout=60) n = len(INDEX_SETTINGS["settings"]["analysis"]["filter"]["bilingual_synonyms"]["synonyms"]) print(f"✓ {n} groupes de synonymes actifs") finally: await client.close() if __name__ == "__main__": asyncio.run(main())