python 向 ElaticScrapy中批量插入数据:
class ElaticSearchPipeline(object):
def process_item(self, item, spider):
es = Elasticsearch([{'host': '10.***.**.***', 'port': 9200}])
print item
data = {
"add_time" : item["add_time"],
# "author" : item["author"],
"content" : item["content"],
"site_name" : item["site_name"],
"title" : item["title"],
"url" : item["url"],
"publish_time" : item["publish_time"]
}
global a
a = a+ 1
res = es.index(index="test-index", doc_type='test', id= a, body=data)
print(res['created'])