Cannot connect to Elasticsearch as a datasource. Getting a 502

Hi,

I am new to grafana and Elasticsearch.
Please, I am having an issue using elasticsearch as a datasource. When I configure the datasource and hit the save & test button I get a 502 error back.

This is what the grafana log says

I am also able to connect to kibana successfully if that helps
This is what I am running
docker image: kibana:6.7.2 and elasticsearch:6.7.2

Thank you for your help

Seems to me the Grafana server can’t connect/communicate with your Elasticsearch instance.

thers is a Chrome plugin named ElasticSearch-head which can test if you can access your es, you can type in your es URL to check if the “http://localhost:9200” connection works well.

I am able to connect to elasticsearch when make a get call to http://localhost:9200
This is my response

{
“name”: “BNoTvkJ”,
“cluster_name”: “docker-cluster”,
“cluster_uuid”: “t9kCygyHSeWZuTrywOQKMQ”,
“version”: {
“number”: “6.7.2”,
“build_flavor”: “default”,
“build_type”: “docker”,
“build_hash”: “56c6e48”,
“build_date”: “2019-04-29T09:05:50.290371Z”,
“build_snapshot”: false,
“lucene_version”: “7.7.0”,
“minimum_wire_compatibility_version”: “5.6.0”,
“minimum_index_compatibility_version”: “5.0.0”
},
“tagline”: “You Know, for Search”
}

Not sure if you have Grafana running on the same computer where you do the call to http://localhost:9200. Otherwise please do a curl/wget request to http://localhost:9200 from the Grafana instance. Alternatively open chrome developer tools and check the console and network tab (failing request) and include details here.

I have grafana and elasticsearch docker instance running in the same computer.
This is the response I get on chrome

I did a shell into the grafana instance and made a call to http://localhost:9200; I got a connection refused.
image

Thanks

This is my docker compose if it helps

Thanks

Think you should use http://elasticsearch:9200 as the Elasticsearch url in Grafana since you’re using a custom network.

3 Likes

Thanks mefraimsson !
Its working now.

My elasticsearch is running on a virtual machine and my grafana is on my localhost. I am getting the Bad GateWay Error when trying to add elasticsearch as a datasource in grafana. as url I use http://[virtual-machine-ip]:9200)
does anyone know how to solve this?

In my environment, the solution I used was to specify the IP address of the Elasticsearch host in the URL instead of the hostname. To determine that, I logged into the grafana pod (‘k exec -n prometheus --stdin --tty prometheus-grafana-xxxx-xxxx – /bin/sh’) and tried to ping “elasticsearch” and “elasticsearch-master”, and both failed. So I got the IP address from ‘k get services -A|grep elasticsearch’.