@@ -30,24 +30,38 @@ function validate_elasticsearch() {
3030
3131    while  [ $retry_count  -lt  $max_retries  ];  do 
3232        print_info " Checking Elasticsearch connection (Attempt $(( retry_count +  1 )) $max_retries )..." 
33-         
34-         health=$( curl -k -s -o /dev/null -w ' %{http_code}' " http://${ES_HOST} :${ES_PORT} /_cluster/health" 2> /dev/null) 
33+ 
34+         local  response_body=$( curl -k -s " http://${ES_HOST} :${ES_PORT} /" 2> /dev/null) 
35+         local  health=$( curl -k -s -o /dev/null -w ' %{http_code}' " http://${ES_HOST} :${ES_PORT} /_cluster/health" 2> /dev/null) 
3536
3637        if  [ " $health " -eq  200 ];  then 
37-             print_success " Successfully connected to Elasticsearch via HTTP" 
38-             export  ES_USE_SSL=false
39-             return  0
38+             if  echo  " $response_body " |  grep -q ' "tagline" *: *"You Know, for Search"' ;  then 
39+                 print_success " Successfully connected to Elasticsearch via HTTP" 
40+                 export  ES_USE_SSL=false
41+                 return  0
42+             else 
43+                 print_error " Connected to a service that is not Elasticsearch" 
44+                 print_error " Found service response: $response_body " 
45+                 return  1
46+             fi 
4047        fi 
4148
4249        print_info " HTTP connection failed, trying HTTPS..." 
50+         response_body=$( curl -k -s " https://${ES_HOST} :${ES_PORT} /" 2> /dev/null) 
4351        health=$( curl -s -o /dev/null -w ' %{http_code}' " https://${ES_HOST} :${ES_PORT} /_cluster/health" 2> /dev/null) 
4452
4553        if  [ " $health " -eq  200 ];  then 
46-             print_success " Successfully connected to Elasticsearch via HTTPS" 
47-             export  ES_USE_SSL=true
48-             return  0
54+             if  echo  " $response_body " |  grep -q ' "tagline" *: *"You Know, for Search"' ;  then 
55+                 print_success " Successfully connected to Elasticsearch via HTTPS" 
56+                 export  ES_USE_SSL=true
57+                 return  0
58+             else 
59+                 print_error " Connected to a service that is not Elasticsearch" 
60+                 print_error " Found service response: $response_body " 
61+                 return  1
62+             fi 
4963        fi 
50-          
64+ 
5165        retry_count=$(( retry_count +  1 )) 
5266        if  [ $retry_count  -lt  $max_retries  ];  then 
5367            print_warning " Connection attempt $retry_count  failed. Waiting ${wait_time}  seconds before retry..." 
@@ -59,7 +73,7 @@ function validate_elasticsearch() {
5973    print_error " Failed to connect to Elasticsearch after $max_retries  attempts:" 
6074    print_error "   - http://${ES_HOST} :${ES_PORT} " 
6175    print_error "   - https://${ES_HOST} :${ES_PORT} " 
62-     print_error " Please ensure:" 
76+     print_error "   Please ensure:" 
6377    print_error "   - Elasticsearch is running" 
6478    print_error "   - ES_HOST and ES_PORT are correctly set" 
6579    print_error "   - Network connectivity is available" 
0 commit comments