During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "for_bulk_insert.py", line 61, in
es.indices.delete(index=index_name, ignore=[400, 404])
File "/home/subham/subhamenv/lib64/python3.6/site-packages/elasticsearch/client/utils.py", line 152, in _wrapped
return func(*args, params=params, headers=headers, **kwargs)
File "/home/subham/subhamenv/lib64/python3.6/site-packages/elasticsearch/client/indices.py", line 286, in delete
"DELETE", _make_path(index), params=params, headers=headers
File "/home/subham/subhamenv/lib64/python3.6/site-packages/elasticsearch/transport.py", line 390, in perform_request
raise e
File "/home/subham/subhamenv/lib64/python3.6/site-packages/elasticsearch/transport.py", line 365, in perform_request
timeout=timeout,
File "/home/subham/subhamenv/lib64/python3.6/site-packages/elasticsearch/connection/http_urllib3.py", line 258, in perform_request
raise ConnectionError("N/A", str(e), e)
elasticsearch.exceptions.ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x7f68bba86358>: Failed to establish a new connection: [Errno 111] Connection refused) caused by: NewConnectionError(<urllib3.connection.HTTPConnection object at 0x7f68bba86358>: Failed to establish a new connection: [Errno 111] Connection refused)
Please format your code as such for easier readability.
"During handling of the above exception, another exception occurred:" What is "above" and what is "another" here? Also adding the relevant code snippet might help to figure out the problem.
#importing Dictionary
import psycopg2
from elasticsearch import Elasticsearch
from elasticsearch import helpers
import datetime
import pandas as pd
from pandas import DataFrame
#Establishing the connection with ELK
es= Elasticsearch([' '], http_auth=(' ', ' '))
#es.cluster.health(wait_for_status='yellow', request_timeout=2)
#establishing the connection
conn = psycopg2.connect( database=' ', user=' ', password=' ', host=' ', port= ' ' )#configured database
if conn:
print ("Connected Successfully")
else:
print ("Connection Not Established")
mydict = create_dict()
query="select * from emr.patient_summarized_test_data_trans Limit 1000"
cursor = conn.cursor()
cursor.execute(query)
result = cursor.fetchall()
df = DataFrame(result,columns=["summarized_test_data_id","package_id","panel_id",
"test_id","loinc_nm","test_type","test_result","patient_id","hos_patient_id"])
json_str = df.to_json(orient='records')
json_records = json.loads(json_str)
es = Elasticsearch()
index_name = 'in-dev-patient-summary-research6'
doctype = 'summary-research6'
es.indices.delete(index=index_name, ignore=[400, 404])
es.indices.create(index=index_name, ignore=400)
action_list = []
for row in json_records:
record ={
'_op_type': 'index',
'_index': index_name,
'_type' : doctype,
'_source': row
}
action_list.append(record)
helpers.bulk(es, action_list,request_timeout=3600)
Output;
File "/home/subham/subhamenv/lib64/python3.6/site-packages/elasticsearch/connection/http_urllib3.py", line 258, in perform_request
raise ConnectionError("N/A", str(e), e)
elasticsearch.exceptions.ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x7f68bba86358>: Failed to establish a new connection: [Errno 111] Connection refused) caused by: NewConnectionError(<urllib3.connection.HTTPConnection object at 0x7f68bba86358>: Failed to establish a new connection: [Errno 111] Connection refused)
What happens if you try a cURL request (curl -u <user>:<password> <host>) from the machine where you are running the Python code against Elasticsearch? This looks like a connection problem — wrong port, firewall, Elasticsearch not bound to the interface you're trying to access,...
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.