Elasticsearch client initialization failed: Failed to connect to Elasticsearch #21192

Closed
opened 2026-02-21 20:11:21 -05:00 by yindo · 2 comments
Owner

Originally created by @comaaxl on GitHub (Dec 20, 2025).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

v1.11.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I deployed Dify on a MacBook M4 and chose Elasticsearch as the vector database. I have also configured the corresponding settings in the .env and docker_compose.yaml files accordingly. However, an error occurs when uploading and parsing documents:
Elasticsearch client initialization failed: Failed to connect to Elasticsearch

Below are the configuration files:

docker-compose.yaml

env.txt

Image

✔️ Expected Behavior

none

Actual Behavior

none

Originally created by @comaaxl on GitHub (Dec 20, 2025). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version v1.11.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce I deployed Dify on a MacBook M4 and chose Elasticsearch as the vector database. I have also configured the corresponding settings in the .env and docker_compose.yaml files accordingly. However, an error occurs when uploading and parsing documents: Elasticsearch client initialization failed: Failed to connect to Elasticsearch Below are the configuration files: [docker-compose.yaml](https://github.com/user-attachments/files/24276122/docker-compose.yaml) [env.txt](https://github.com/user-attachments/files/24276127/env.txt) <img width="785" height="603" alt="Image" src="https://github.com/user-attachments/assets/7e7cd862-d16d-4533-b55b-61f49c88b8df" /> ### ✔️ Expected Behavior none ### ❌ Actual Behavior none
yindo added the 🐞 bug label 2026-02-21 20:11:21 -05:00
yindo closed this issue 2026-02-21 20:11:21 -05:00
Author
Owner

@comaaxl commented on GitHub (Dec 20, 2025):

By the way, I'm running the containers via Docker Desktop locally installed on my Mac, not on a server. I'm wondering if some configurations like 127.0.0.1 or localhost aren't set correctly. Could you please help check this issue? Thank you!

@comaaxl commented on GitHub (Dec 20, 2025): By the way, I'm running the containers via Docker Desktop locally installed on my Mac, not on a server. I'm wondering if some configurations like 127.0.0.1 or localhost aren't set correctly. Could you please help check this issue? Thank you!
Author
Owner

@dosubot[bot] commented on GitHub (Dec 20, 2025):

Yes, this is a common Docker networking issue on Mac. Inside Docker containers, localhost and 127.0.0.1 refer to the container itself, not your Mac. If Elasticsearch is running as a container in the same Docker Compose setup, you should set ELASTICSEARCH_HOST to the service name (usually elasticsearch), not localhost or 127.0.0.1—this allows Dify to reach Elasticsearch over the Docker network. If you need to connect to a service running on your Mac (outside Docker), use host.docker.internal instead of localhost or 127.0.0.1 reference.

Make sure your docker-compose.yaml exposes Elasticsearch’s port (e.g., ports: - "9200:9200"), and update your .env so ELASTICSEARCH_HOST=elasticsearch (for container-to-container) or ELASTICSEARCH_HOST=host.docker.internal (for host access). After making changes, restart your containers with docker-compose down && docker-compose up -d reference.

You can check port mapping with docker ps—look for something like 0.0.0.0:9200->9200/tcp for Elasticsearch. If you still see connection errors, check the logs for both Dify and Elasticsearch containers for more details.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Dec 20, 2025): <!-- Answer --> Yes, this is a common Docker networking issue on Mac. Inside Docker containers, `localhost` and `127.0.0.1` refer to the container itself, not your Mac. If Elasticsearch is running as a container in the same Docker Compose setup, you should set `ELASTICSEARCH_HOST` to the service name (usually `elasticsearch`), not `localhost` or `127.0.0.1`—this allows Dify to reach Elasticsearch over the Docker network. If you need to connect to a service running on your Mac (outside Docker), use `host.docker.internal` instead of `localhost` or `127.0.0.1` [reference](https://github.com/langgenius/dify-official-plugins/issues/1542). Make sure your `docker-compose.yaml` exposes Elasticsearch’s port (e.g., `ports: - "9200:9200"`), and update your `.env` so `ELASTICSEARCH_HOST=elasticsearch` (for container-to-container) or `ELASTICSEARCH_HOST=host.docker.internal` (for host access). After making changes, restart your containers with `docker-compose down && docker-compose up -d` [reference](https://github.com/langgenius/dify-docs/issues/471#issuecomment-3344509043). You can check port mapping with `docker ps`—look for something like `0.0.0.0:9200->9200/tcp` for Elasticsearch. If you still see connection errors, check the logs for both Dify and Elasticsearch containers for more details. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/ca7e5bd7-f57f-4e32-a6dd-692b486e0808?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/ca7e5bd7-f57f-4e32-a6dd-692b486e0808?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/ca7e5bd7-f57f-4e32-a6dd-692b486e0808?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/ca7e5bd7-f57f-4e32-a6dd-692b486e0808?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/ca7e5bd7-f57f-4e32-a6dd-692b486e0808?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/ca7e5bd7-f57f-4e32-a6dd-692b486e0808?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/ca7e5bd7-f57f-4e32-a6dd-692b486e0808?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=Yes%2C%20this%20is%20a%20common%20Docker%20networking%20issue%20on%20Mac.%20Inside%20Docker%20containers%2C%20%60localhost%60%20and%20%60127.0.0.1%60%20refer%20to%20the%20container%20itself%2C%20not%20your%20Mac.%20If%20Elasticsearch%20is%20running%20as%20a%20container%20in%20the%20same%20Docker%20Compose%20setup%2C%20you%20should%20set%20%60ELASTICSEARCH_HOST%60%20to%20the%20service%20name%20%28usually%20%60elasticsearch%60%29%2C%20not%20%60localhost%60%20or%20%60127.0.0.1%60%E2%80%94this%20allows%20Dify%20to%20reach%20Elasticsearch%20over%20the%20Docker%20network.%20If%20you%20need%20to%20connect%20to%20a%20service%20running%20on%20your%20Mac%20%28outside%20Docker%29%2C%20use%20%60host.docker.internal%60%20instead%20of%20%60localhost%60%20or%20%60127.0.0.1%60%C2%A0%5Breference%5D%28https%3A//github.com/langgenius/dify-official-plugins/issues/1542%29.%0A%0AMake%20sure%20your%20%60docker-compose.yaml%60%20exposes%20Elasticsearch%E2%80%99s%20port%20%28e.g.%2C%20%60ports%3A%20-%20%229200%3A9200%22%60%29%2C%20and%20update%20your%20%60.env%60%20so%20%60ELASTICSEARCH_HOST%3Delasticsearch%60%20%28for%20container-to-container%29%20or%20%60ELASTICSEARCH_HOST%3Dhost.docker.internal%60%20%28for%20host%20access%29.%20After%20making%20changes%2C%20restart%20your%20containers%20with%20%60docker-compose%20down%20%26%26%20docker-compose%20up%20-d%60%C2%A0%5Breference%5D%28https%3A//github.com/langgenius/dify-docs/issues/471%23issuecomment-3344509043%29.%0A%0AYou%20can%20check%20port%20mapping%20with%20%60docker%20ps%60%E2%80%94look%20for%20something%20like%20%600.0.0.0%3A9200-%3E9200/tcp%60%20for%20Elasticsearch.%20If%20you%20still%20see%20connection%20errors%2C%20check%20the%20logs%20for%20both%20Dify%20and%20Elasticsearch%20containers%20for%20more%20details.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/29961)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#21192