from datetime import datetime
from elasticsearch import Elasticsearch
es = Elasticsearch()
doc = {
\'author\': \'kimchy\',
\'text\': \'Elasticsearch: cool.
Two options that help:
Setting a timeout solved this problem for me. Note that newer versions need a unit, e.g. timeout="60s"
:
es.index(index=index_name, doc_type="domains", id=domain.id, body=body, timeout="60s")
Without a unit, for example by setting timeout=60
, you'll get
elasticsearch.exceptions.RequestError: RequestError(400, 'illegal_argument_exception', 'failed to parse setting [timeout] with value [60] as a time value: unit is missing or unrecognized')
It also helps to reduce the text length, e.g. by cutting of long texts, so elastic can store the text faster which will avoid timeouts, too:
es.index(index=index_name, doc_type="domains", id=domain.id, body=text[:5000], timeout="60s")