python 2.7 - elasticsearch exception SerializationError -
from python script sending data elasticsearch server
this me connect es
es = elasticsearch('localhost:9200',use_ssl=false,verify_certs=true)
and using bellow code able send data local es server
es.index(index='alertnagios', doc_type='nagios', body=jsonvalue)
but when trying send data cloud es server,the script executing fine , indexing few documents after indexing few documents getting following error
traceback (most recent call last): file "scriptfile.py", line 78, in <module> es.index(index='test', doc_type='test123', body=jsonvalue) file "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 73, in _wrapped return func(*args, params=params, **kwargs) file "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/__init__.py", line 298, in index _make_path(index, doc_type, id), params=params, body=body) file "/usr/local/lib/python2.7/dist-packages/elasticsearch/transport.py", line 342, in perform_request data = self.deserializer.loads(data, headers.get('content-type')) file "/usr/local/lib/python2.7/dist-packages/elasticsearch/serializer.py", line 76, in loads return deserializer.loads(s) file "/usr/local/lib/python2.7/dist-packages/elasticsearch/serializer.py", line 40, in loads raise serializationerror(s, e) elasticsearch.exceptions.serializationerror: (u'order=0></iframe>', jsondecodeerror('no json object decoded: line 1 column 0 (char 0)',))
the same script working fine when sending data localhost es server , don't know why not working when sending data cloud instance
please me
the problem resolved using bulk indexing method ,when indexing local server won't matter if index documents 1 after other ,but while indexing cloud instance have follow bulk indexing method overcome memory issues , connection issues
if follow bulk indexing method index documnets once elasticsearch , no need open connection again , again,it won't take time.
here code
from elasticsearch import elasticsearch,helpers actions = [] jsonobject= { '_index': 'index', '_type': 'index123', '_source':jsondata } actions.append(jsonobject) helpers.bulk(es, actions, chunk_size=1000, request_timeout=200)
wiki
Comments
Post a Comment