2017-04-24 36 views
0

试图让批量渗透功能适用于Elasticsearch-py(即mpercolate),但一直未能在线找到示例。我能够使用渗滤液功能,这样我就可以得到这个工作:Elasticsearch-py批量渗透功能

doc = {'doc' : {'field1' : 'this is a value', 'field2' : 'this is another value'}} 
res = es.percolate(index = 'my_index', doc_type = 'my_doc_type', body = doc) 

到目前为止我读过的文档似乎暗示,如果我想做一个批量提交,我需要发标题和正文作为字符串,由换行符分隔。因此,我试过:

head = {'percolate' : {'index' : 'my_index', 'type' : 'my_doc_type'}}  
doc = {'doc' : {'field1' : 'this is a value', 'field2' : 'this is another value'}} 
doc2 = {'doc' : {'field1' : 'values and values', 'field2' : 'billions of values'}} 

query_list = [head, doc, head, doc2] 
my_body = '\n'.join([str(qry) for qry in query_list]) 

res = es.mpercolate(body = my_body) 

它给了我一个通用的“elasticsearch.exceptions.TransportError”。任何人都有我可以适应的工作示例?

回答

0

你不必自己序列化数据,只是通过在query_list的机构,它应该做的正确的事情