# How to connect Google Colab to Elasticsearch

**URL:** <https://discuss.elastic.co/t/how-to-connect-google-colab-to-elasticsearch/315618>\
**Category:** Elasticsearch\
**Created:** [October 1, 2022, 2:24pm UTC](https://discuss.elastic.co/t/how-to-connect-google-colab-to-elasticsearch/315618 "2022-10-01T14:24:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shivang.ahd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shivang.ahd/32/110992_2.png) [@shivang.ahd](https://discuss.elastic.co/u/shivang.ahd)\
**Post date:** [October 1, 2022, 2:24pm UTC](https://discuss.elastic.co/t/how-to-connect-google-colab-to-elasticsearch/315618/1 "2022-10-01T14:24:43Z")

</div>

Hi,

How to connect Google Colab to Elasticsearch.

I have followed few ways, but getting error for all the ways.

One of the code is as below:-

```auto
!pip install Elasticsearch -q

# download elasticsearch
!wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.1-linux-x86_64.tar.gz -q
!tar -xzf elasticsearch-7.9.1-linux-x86_64.tar.gz
!chown -R daemon:daemon elasticsearch-7.9.1

# start server
import os
from subprocess import Popen, PIPE, STDOUT
es_server = Popen(['elasticsearch-7.9.1/bin/elasticsearch'], 
                  stdout=PIPE, stderr=STDOUT,
                  preexec_fn=lambda: os.setuid(1)
                 )
# wait a bit then test
!curl -X GET "localhost:9200/"

# client-side
!pip install elasticsearch -q
 # got True
from elasticsearch import Elasticsearch
from datetime import datetime
es = Elasticsearch([{'host': 'localhost' , 'port': 9200, "scheme": "http"}])
es.ping() 

```

**For the above script, I am getting "False" as output..**

---

<div class="post-metadata">

**Author:** ![shivang.ahd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shivang.ahd/32/110992_2.png) [@shivang.ahd](https://discuss.elastic.co/u/shivang.ahd)\
**Post date:** [October 1, 2022, 6:07pm UTC](https://discuss.elastic.co/t/how-to-connect-google-colab-to-elasticsearch/315618/2 "2022-10-01T18:07:15Z")

</div>

Getting below output in Google Colab :-

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/5/45f3b98ac86ab3ea5bf07f658aedaaf403e923c0.png)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/f/ff10d1e6b6142176dafcac24dbefbce1f6605b2f.png)

---

<div class="post-metadata">

**Author:** ![shivang.ahd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shivang.ahd/32/110992_2.png) [@shivang.ahd](https://discuss.elastic.co/u/shivang.ahd)\
**Post date:** [October 1, 2022, 6:21pm UTC](https://discuss.elastic.co/t/how-to-connect-google-colab-to-elasticsearch/315618/3 "2022-10-01T18:21:29Z")

</div>

Below are the different ways tried by me:-

> <https://gist.github.com/korakot/15fe4f18d0e0f53d7b834ef797880500>
>
> There are more than three files. show original

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 29, 2022, 6:22pm UTC](https://discuss.elastic.co/t/how-to-connect-google-colab-to-elasticsearch/315618/4 "2022-10-29T18:22:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
