Connection Timeout with Elasticsearch

前端 未结 9 2041
刺人心
刺人心 2020-12-04 21:01
from datetime import datetime
from elasticsearch import Elasticsearch
es = Elasticsearch()

doc = {
    \'author\': \'kimchy\',
    \'text\': \'Elasticsearch: cool.          


        
相关标签:
9条回答
  • 2020-12-04 21:05

    Try setting timeout in Elasticsearch initialization:

    es = Elasticsearch([{'host': HOST_ADDRESS, 'port': THE_PORT}], timeout=30)
    

    You can even set retry_on_timeout to True and give the max_retries an optional number:

    es = Elasticsearch([{'host': HOST_ADDRESS, 'port': THE_PORT}], timeout=30, max_retries=10, retry_on_timeout=True)
    
    0 讨论(0)
  • 2020-12-04 21:05

    elasticsearch.exceptions.ConnectionTimeout: ConnectionTimeout caused by - ReadTimeoutError(HTTPConnectionPool(host='localhost', port=9200): Read timed out. (read timeout=10)) mean the request didn't end in the specified time (by default, timeout=10).

    This will work with 30 seconds :

    res = es.index(index="test-index", doc_type='tweet', id=1, body=doc, timeout=30)

    0 讨论(0)
  • 2020-12-04 21:05

    The reasons for the timeout could be many and it seems worth checking the logs on elasticsearch side (logs/elasticsearch.log) to see the detailed error. In our case, the error on ES was:

    primary shard is not active Timeout: [1m]
    

    As described in this post, this was because our disk was full. We had resized it (and the partition) a day ago to take care of that but ES needs to be restarted if the high/low watermark has been hit once (we are on 5.5.x) which we had not done.

    Simply restarting the ES on production resolved the issue for us.

    0 讨论(0)
  • 2020-12-04 21:12

    The connection timed out problem could occur if you are using Amazon Elastic Search service.

    es = Elasticsearch([{'host': 'xxxxxx.us-east-1.es.amazonaws.com', 'port': 443,  'use_ssl': True}])
    

    The above python code where you override the default port from 9200 to 443 and setting the SSL to true will resolve the issue.

    If no port is specified, it is trying to connect to the port 9200 in the specified host and fails after time out

    0 讨论(0)
  • 2020-12-04 21:13

    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)
    
    0 讨论(0)
  • 2020-12-04 21:16

    This is nothing to do with increasing your timeout to 30 seconds. Do people actually think that elastic search should need up to 30 seconds to return one tiny hit?

    The way I fixed this problem was go to config/elasticsearch.yml uncomment the following

    http.port: 9200
    network.host: 'localhost' 
    

    Network.host might be set to 192.168.0.1 which might work But I just changed it to 'localhost'

    0 讨论(0)
提交回复
热议问题