Skip to content

Commit 84a093b

Browse files
author
Dylan Huang
committed
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.
1 parent 518d527 commit 84a093b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

eval_protocol/cli_commands/logs.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ def logs_command(args):
3131
)
3232

3333
elasticsearch_config = create_elasticsearch_config_from_env()
34+
# Ensure index exists with correct mapping, mirroring Docker setup path
35+
try:
36+
from eval_protocol.log_utils.elasticsearch_index_manager import (
37+
ElasticsearchIndexManager,
38+
)
39+
40+
index_manager = ElasticsearchIndexManager(
41+
elasticsearch_config.url,
42+
elasticsearch_config.index_name,
43+
elasticsearch_config.api_key,
44+
)
45+
created = index_manager.create_logging_index_mapping()
46+
if created:
47+
print(
48+
f"🧭 Verified Elasticsearch index '{elasticsearch_config.index_name}' mapping (created or already correct)"
49+
)
50+
else:
51+
print(
52+
f"⚠️ Could not verify/create mapping for index '{elasticsearch_config.index_name}'. Searches may behave unexpectedly."
53+
)
54+
except Exception as e:
55+
print(f"⚠️ Failed to ensure index mapping via IndexManager: {e}")
3456
elif not getattr(args, "disable_elasticsearch_setup", False):
3557
# Default behavior: start or connect to local Elasticsearch via Docker helper
3658
from eval_protocol.pytest.elasticsearch_setup import ElasticsearchSetup

0 commit comments

Comments
 (0)