APM- server not connecting to the elasticsearch which is running on the same server

**Kibana version**: 8.12.2
**Elasticsearch version**: 8.12.2
**APM Server version**:8.12.2
**APM Agent language and version**:
**Browser version**:
**Original install method - download page
**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**:
**Errors in browser console (if relevant)**:
apm-server test output
elasticsearch: http://localhost:9200...
  parse url... OK
  connection...
    parse host... OK
    dns lookup... OK
    addresses: 127.0.0.1
    dial up... OK
  TLS... WARN secure connection disabled
  talk to server... ERROR Get "http://localhost:9200": EOF
**Provide logs and/or server output (if relevant)**:
Feb 23 09:42:35 sm-elk-apm apm-server[299744]: {"log.level":"error","@timestamp":"2024-02-23T09:42:35.741Z","log.logger":"beater","log.origin":{"function":"github.com/elastic/apm-server/internal/beater.waitReady","file.name":"beater/waitready.go","file.line":64},"message":"precondition failed: EOF","service.name":"apm-server","ecs.version":"1.6.0"}
Feb 23 09:42:44 sm-elk-apm apm-server[299744]: {"log.level":"error","@timestamp":"2024-02-23T09:42:44.900Z","log.logger":"agentcfg","log.origin":{"function":"github.com/elastic/apm-server/internal/agentcfg.(*ElasticsearchFetcher).Run.func1","file.name":"agentcfg/elasticsearch.go","file.line":150},"message":"refresh cache error: context deadline exceeded","service.name":"apm-server","ecs.version":"1.6.0"}
Feb 23 09:42:50 sm-elk-apm apm-server[299744]: {"log.level":"error","@timestamp":"2024-02-23T09:42:50.750Z","log.logger":"beater","log.origin":{"function":"github.com/elastic/apm-server/internal/beater.waitReady","file.name":"beater/waitready.go","file.line":64},"message":"precondition failed: EOF","service.name":"apm-server","ecs.version":"1.6.0"}
Feb 23 09:43:05 sm-elk-apm apm-server[299744]: {"log.level":"error","@timestamp":"2024-02-23T09:43:05.758Z","log.logger":"beater","log.origin":{"function":"github.com/elastic/apm-server/internal/beater.waitReady","file.name":"beater/waitready.go","file.line":64},"message":"precondition failed: EOF","service.name":"apm-server","ecs.version":"1.6.0"}
Feb 23 09:43:14 sm-elk-apm apm-server[299744]: {"log.level":"error","@timestamp":"2024-02-23T09:43:14.899Z","log.logger":"agentcfg","log.origin":{"function":"github.com/elastic/apm-server/internal/agentcfg.(*ElasticsearchFetcher).Run.func1","file.name":"agentcfg/elasticsearch.go","file.line":150},"message":"refresh cache error: context deadline exceeded","service.name":"apm-server","ecs.version":"1.6.0"}
Feb 23 09:43:20 sm-elk-apm apm-server[299744]: {"log.level":"error","@timestamp":"2024-02-23T09:43:20.767Z","log.logger":"beater","log.origin":{"function":"github.com/elastic/apm-server/internal/beater.waitReady","file.name":"beater/waitready.go","file.line":64},"message":"precondition failed: EOF","service.name":"apm-server","ecs.version":"1.6.0"}
Feb 23 09:43:35 sm-elk-apm apm-server[299744]: {"log.level":"error","@timestamp":"2024-02-23T09:43:35.774Z","log.logger":"beater","log.origin":{"function":"github.com/elastic/apm-server/internal/beater.waitReady","file.name":"beater/waitready.go","file.line":64},"message":"precondition failed: EOF","service.name":"apm-server","ecs.version":"1.6.0"}
Feb 23 09:43:44 sm-elk-apm apm-server[299744]: {"log.level":"error","@timestamp":"2024-02-23T09:43:44.899Z","log.logger":"agentcfg","log.origin":{"function":"github.com/elastic/apm-server/internal/agentcfg.(*ElasticsearchFetcher).Run.func1","file.name":"agentcfg/elasticsearch.go","file.line":150},"message":"refresh cache error: context deadline exceeded","service.name":"apm-server","ecs.version":"1.6.0"}
Feb 23 09:43:50 sm-elk-apm apm-server[299744]: {"log.level":"error","@timestamp":"2024-02-23T09:43:50.783Z","log.logger":"beater","log.origin":{"function":"github.com/elastic/apm-server/internal/beater.waitReady","file.name":"beater/waitready.go","file.line":64},"message":"precondition failed: EOF","service.name":"apm-server","ecs.version":"1.6.0"}
Feb 23 09:44:05 sm-elk-apm apm-server[299744]: {"log.level":"error","@timestamp":"2024-02-23T09:44:05.793Z","log.logger":"beater","log.origin":{"function":"github.com/elastic/apm-server/internal/beater.waitReady","file.name":"beater/waitready.go","file.line":64},"message":"precondition failed: EOF","service.name":"apm-server","ecs.version":"1.6.0"}```