From 84a093b3a9ebc434268b608d07d5a11028bb135b Mon Sep 17 00:00:00 2001 From: Dylan Huang Date: Fri, 10 Oct 2025 16:52:42 -0700 Subject: [PATCH] Add Elasticsearch index mapping verification in logs command - Implemented a check to ensure the Elasticsearch index exists with the correct mapping, mirroring the Docker setup path. - Added error handling to notify if the mapping could not be verified or created. - Enhanced user feedback for index mapping status during logs command execution. --- eval_protocol/cli_commands/logs.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/eval_protocol/cli_commands/logs.py b/eval_protocol/cli_commands/logs.py index 16d6d6de..7e2d668a 100644 --- a/eval_protocol/cli_commands/logs.py +++ b/eval_protocol/cli_commands/logs.py @@ -31,6 +31,28 @@ def logs_command(args): ) elasticsearch_config = create_elasticsearch_config_from_env() + # Ensure index exists with correct mapping, mirroring Docker setup path + try: + from eval_protocol.log_utils.elasticsearch_index_manager import ( + ElasticsearchIndexManager, + ) + + index_manager = ElasticsearchIndexManager( + elasticsearch_config.url, + elasticsearch_config.index_name, + elasticsearch_config.api_key, + ) + created = index_manager.create_logging_index_mapping() + if created: + print( + f"🧭 Verified Elasticsearch index '{elasticsearch_config.index_name}' mapping (created or already correct)" + ) + else: + print( + f"⚠️ Could not verify/create mapping for index '{elasticsearch_config.index_name}'. Searches may behave unexpectedly." + ) + except Exception as e: + print(f"⚠️ Failed to ensure index mapping via IndexManager: {e}") elif not getattr(args, "disable_elasticsearch_setup", False): # Default behavior: start or connect to local Elasticsearch via Docker helper from eval_protocol.pytest.elasticsearch_setup import ElasticsearchSetup