How to connect Google Colab to Elasticsearch

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:-

!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..

Getting below output in Google Colab :-

Below are the different ways tried by me:-

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