python - Cannot index document in elasticsearch while performing string operation -


i have index documents in elasticsearch stored in file, , indexing documents while performing string operation on it. (i have partition line , use splits separately)

rec = open(file)  line in rec:      val_1 = line.partition(' ')[0].strip()     val_2 = line.partition(' ')[1].strip()     #print   str(val_1) + " " + str(val_2)     es.index(index="test", doc_type="trial", id = val_1, body = val2) 

i can print line, cannot index reason. throws out following error.

file "c:\python27\lib\site-packages\elasticsearch\client\utils.py", line 69, in >_wrapped return func(*args, params=params, **kwargs)

file "c:\python27\lib\site-packages\elasticsearch\client__init__.py", line >261, in index _make_path(index, doc_type, id), params=params,body=body)

file "c:\python27\lib\site-packages\elasticsearch\transport.py", line 307, in >perform_request status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)

this error same if perform operations inside loop

es.index(index = "test", doc_type= "trial", id = line.partition(' ')[0].strip(), body = line.partition(' ')[2].strip()) 

am sending parameters in wrong way? should start looking fix this.

i found solution: silly mistake really. wrote

es.index(index="test", doc_type="trial", id = val_1, body = val2) 

what missed format body properly. should

es.index(index="test", doc_type="trial", id = val_1, body = {"name": val2 } ) 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -