Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection Timeout with Elasticsearch

from datetime import datetime from elasticsearch import Elasticsearch es = Elasticsearch()  doc = {     'author': 'kimchy',     'text': 'Elasticsearch: cool. bonsai cool.',     'timestamp': datetime(2010, 10, 10, 10, 10, 10) } res = es.index(index="test-index", doc_type='tweet', id=1, body=doc) print(res['created']) 

This simples code is returning the following error:

elasticsearch.exceptions.ConnectionTimeout: ConnectionTimeout caused by - ReadTimeoutError(HTTPConnectionPool(host='localhost', port=9200): Read timed out. (read timeout=10)) 

Very strange, because the server is ready and set (http://localhost:9200/ is returning some json).

like image 282
Johann Gomes Avatar asked Feb 02 '15 21:02

Johann Gomes


People also ask

What is socket timeout?

socket timeout — a maximum time of inactivity between two data packets when exchanging data with a server.

What is the difference between Readtimeout and Connecttimeout?

The connection timeout is the timeout in making the initial connection; i.e. completing the TCP connection handshake. The read timeout is the timeout on waiting to read data1.

What is connect time out?

A server connection timeout means that a server is taking too long to reply to a data request made from another device. Timeouts are not a reply message: they show up when there isn't a reply and a server request is not fulfilled in a predetermined length of time.

How long should a connection timeout be?

The default value is 60 seconds. If the value of this stanza entry is set to 0 (or not set), connection timeouts between data fragments are governed instead by the client-connect-timeout stanza entry. The exception to this rule occurs for responses returned over HTTP (TCP).


1 Answers

By default, the timeout value is set to 10 secs. If one wants to change the global timeout value, this can be achieved by setting the flag timeout=your-time while creating the object.

If you have already created the object without specifying the timeout value, then you can set the timeout value for particular request by using request_timeout=your-time flag in the query.

es.search(index="my_index",           doc_type="document",           body=get_req_body(),           request_timeout=30) 
like image 99
Rahul Avatar answered Oct 13 '22 15:10

Rahul