shivang.ahd
(Shivang Shrivastav)
October 1, 2022, 2:24pm
1
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..
shivang.ahd
(Shivang Shrivastav)
October 1, 2022, 6:07pm
2
Getting below output in Google Colab :-
shivang.ahd
(Shivang Shrivastav)
October 1, 2022, 6:21pm
3
Below are the different ways tried by me:-
es.py
# install es server
!apt install default-jdk > /dev/null
!wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.4.tar.gz -q --show-progress
!tar -xzf elasticsearch-6.5.4.tar.gz
!chown -R daemon:daemon elasticsearch-6.5.4
# start server
import os
from subprocess import Popen, PIPE, STDOUT
es_server = Popen(['elasticsearch-6.5.4/bin/elasticsearch'],
stdout=PIPE, stderr=STDOUT,
This file has been truncated. show original
es7.py
!wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.0-linux-x86_64.tar.gz -q
!tar -xzf elasticsearch-7.0.0-linux-x86_64.tar.gz
!chown -R daemon:daemon elasticsearch-7.0.0
# start server
import os
from subprocess import Popen, PIPE, STDOUT
es_server = Popen(['elasticsearch-7.0.0/bin/elasticsearch'],
stdout=PIPE, stderr=STDOUT,
preexec_fn=lambda: os.setuid(1) # as daemon
)
This file has been truncated. show original
magic.py
from requests import models, Session, Request
from urllib.parse import urljoin
from IPython.core.magic import register_cell_magic
# to display json response
models.Response._repr_html_ = lambda rsp: """
<script src="https://rawgit.com/caldwell/renderjson/master/renderjson.js"></script>
<script>
renderjson.set_show_to_level(1)
document.body.appendChild(renderjson(%s))
This file has been truncated. show original
There are more than three files. show original
system
(system)
Closed
October 29, 2022, 6:22pm
4
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.