Sebastian
Sebastian

Reputation: 1833

Write to elastic search from inside Django view

I'm trying to sync a local SQLite database-entry with an elastic search index.

Here is the view:

def sync_model(request, model_id):
    data = create_json(model_id)
    es = Elasticsearch(hosts=[{'host': 'my_host', 'port': '9200'}])
    res = es.index(index='my_index', doc_type='my_doctype', id=model_id, body=data)
    return redirect('/')

And error at line 4:

ConnectionError(: Failed to establish a new connection: getaddrinfo() argument 2 must be integer or string) caused by: NewConnectionError(: Failed to establish a new connection: getaddrinfo() argument 2 must be integer or string)

The put to elastic search works normally. Am I missing knowledge that doesn't allow this behavior inside Django? Any help would be much appreciated

Upvotes: 0

Views: 121

Answers (1)

mickl
mickl

Reputation: 49945

Driver expects port to be specified as integer. Checkout docs example

es = Elasticsearch(
   hosts=[{'host': host, 'port': 443}],
   http_auth=awsauth,
   use_ssl=True,
   verify_certs=True,
   connection_class=RequestsHttpConnection
)

Upvotes: 1

Related Questions