摘要: 设想这样一个场景: 你创建了10个子线程,每个子线程分别爬一个网站,一开始所有子线程都是阻塞等待。一旦某个事件发生:例如有人在网页上点了一个按钮,或者某人在命令行输入了一个命令,10个爬虫同时开始工作。 肯定有人会想到用Redis来实现这个开关:所有子线程全部监控Redis中名为start_craw 阅读全文
posted @ 2020-01-16 22:50 阿布_alone 阅读(4262) 评论(0) 推荐(0) 编辑
摘要: 当我们在Python里面写文件时,我们常用的模式为 w模式,这种模式下,如果文件不存在,就会生成文件;如果文件已经存在,就会直接覆盖。 有时候,如果文件已经存在,直接覆盖文件可能会导致重要数据丢失。你不希望再覆盖文件,那么你可能会这样写代码: import os if os.path.exists( 阅读全文
posted @ 2020-01-16 22:49 阿布_alone 阅读(1386) 评论(0) 推荐(0) 编辑
摘要: 当我们使用 Elasticsearch-py 批量插入数据到 ES 的时候,我们常常使用它的 helpers模块里面的bulk函数。其使用方法如下: from elasticsearch import helpers, Elasticsearch es = Elasticsearch(xxx) de 阅读全文
posted @ 2020-01-16 22:39 阿布_alone 阅读(3373) 评论(0) 推荐(0) 编辑
摘要: 当我们使用ES批量插入数据的时候,一般会这样写代码: from elasticsearch import Elasticsearch,helpers es =Elasticsearch(hosts=[{'host':'localhost','port':9200}]) def gendata(): 阅读全文
posted @ 2020-01-16 22:36 阿布_alone 阅读(4999) 评论(0) 推荐(1) 编辑
摘要: 对图7-1所示的数据集exampledata1,使用聚合操作实现以下功能: (1)不返回_id字段,只返回age和sex字段。 (2)所有age大于28的记录,只返回age和sex。 (3)在$match返回的字段中,添加一个新的字段“hello”,值为“world”。 (4)在$match返回的字 阅读全文
posted @ 2020-01-16 01:26 阿布_alone 阅读(512) 评论(0) 推荐(0) 编辑
摘要: 全文搜索属于最常见的需求,开源的 Elasticsearch (以下简称 Elastic)是目前全文搜索引擎的首选。 它可以快速地储存、搜索和分析海量数据。维基百科、Stack Overflow、Github 都采用它。 Elastic 的底层是开源库 Lucene。但是,你没法直接用 Lucene 阅读全文
posted @ 2020-01-16 00:38 阿布_alone 阅读(360) 评论(0) 推荐(0) 编辑
TOP