Make sure the kibana version matches the elasticsearch version. To find ES version run
curl http://127.0.0.1:9200
If elasticsearch is running on localhost port 9200.
If you get a similar error like below
... {"type":"log","@timestamp":"2022-10-10T08:19:10Z","tags":["info","savedobjects-service"],"pid":7,"message":"Creating index .kibana_2."} {"type":"log","@timestamp":"2022-10-10T08:19:10Z","tags":["info","savedobjects-service"],"pid":7,"message":"Detected mapping change in \"properties.task\""} {"type":"log","@timestamp":"2022-10-10T08:19:10Z","tags":["error","elasticsearch","data"],"pid":7,"message":"[resource_already_exists_exception]: index [.kibana_2/7OQprmYSRFyDsriszsannw] already exists"} {"type":"log","@timestamp":"2022-10-10T08:19:10Z","tags":["warning","savedobjects-service"],"pid":7,"message":"Unable to connect to Elasticsearch. Error: resource_already_exists_exception"} {"type":"log","@timestamp":"2022-10-10T08:19:10Z","tags":["warning","savedobjects-service"],"pid":7,"message":"Another Kibana instance appears to be migrating the index. Waiting for that migration to complete. If no other Kibana instance is attempting migrations, you can get past this message by deleting index .kibana_2 and restarting Kibana."} {"type":"log","@timestamp":"2022-10-10T08:19:12Z","tags":["info","savedobjects-service"],"pid":7,"message":"Detected mapping change in \"properties.task\""} {"type":"log","@timestamp":"2022-10-10T08:19:13Z","tags":["info","savedobjects-service"],"pid":7,"message":"Detected mapping change in \"properties.task\""} ...
it can be resolved by deleting the mentioned index, e.g.
curl -XDELETE 'localhost:9200/.kibana_2?pretty'