上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 49 下一页
摘要: python读取文件指定行内容 import linecache text=linecache.getline(r'C:\Users\Administrator\Desktop\SourceCodeofMongoRedis\chapter_5\generate_string.py',10) 第十行内 阅读全文
posted @ 2020-03-01 23:52 阿布_alone 阅读(8991) 评论(0) 推荐(0) 编辑
摘要: 一.关于集群的基本操作 #!/usr/bin/env python # -*- coding: utf-8 -*- # author tom from elasticsearch import Elasticsearch from pprint import pprint # 连接es,直接传一个i 阅读全文
posted @ 2020-01-24 00:24 阿布_alone 阅读(2883) 评论(0) 推荐(0) 编辑
摘要: 1. 前言 在执行一些 IO 密集型任务的时候,程序常常会因为等待 IO 而阻塞。比如在网络爬虫中,如果我们使用 requests 库来进行请求的话,如果网站响应速度过慢,程序一直在等待网站响应,最后导致其爬取效率是非常非常低的。 为了解决这类问题,本文就来探讨一下 Python 中异步协程来加速的 阅读全文
posted @ 2020-01-23 19:36 阿布_alone 阅读(824) 评论(0) 推荐(0) 编辑
摘要: 设想这样一个场景: 你创建了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) 编辑
摘要: Elasticsearch下载地址: https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.1.1-linux-x86_64.tar.gz 解压elasticsearch-7.1.1-linux-x86_64.tar 阅读全文
posted @ 2020-01-15 00:31 阿布_alone 阅读(2084) 评论(0) 推荐(0) 编辑
上一页 1 ··· 17 18 19 20 21 22 23 24 25 ··· 49 下一页
TOP