python 向 ElaticScrapy中批量插入数据

来源:互联网 发布:js获取当前浏览器 编辑:程序博客网 时间:2024/06/07 04:42
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'])      
原创粉丝点击