python 广告滚动,使用python客户端弹性搜索滚动
When scrolling in elasticsearch it is important to provide at each scroll the latest scroll_id:
The initial search request and each subsequent scroll request returns
a new scroll_id — only the most recent scroll_id should be used.
The following example (taken from here) puzzle me. First, the srolling initialization:
rs = es.search(index=['tweets-2014-04-12','tweets-2014-04-13'],
scroll='10s',
search_type='scan',
size=100,
preference='_primary_first',
body={
"fields" : ["created_at", "entities.urls.expanded_url", "user.id_str"],
"query" : {
"wildcard" : { "entities.urls.expanded_url" : "*.ru" }
}
}
)
sid = rs['_scroll_id']
and then the looping:
tweets = [] while (1):
try:
rs = es.scroll(scroll_id=sid, scroll='10s')
tweets += rs['hits']['hits']
except:
break
It works, but I don't see where sid is updated... I believe that it happens internally, in the python client; but I don't understand how it works...
解决方案
In fact the code has a bug in it - in order to use the scroll feature correctly you are supposed to use the new scroll_id returned with each new call in the next call to scroll(), not reuse the first one:
Important
The initial search request and each subsequent scroll request returns
a new scroll_id — only the most recent scroll_id should be used.
It's working because Elasticsearch does not always change the scroll_id in between calls and can for smaller result sets return the same scroll_id as was originally returned for some time. This discussion from last year is between two other users seeing the same issue, the same scroll_id being returned for awhile:
So while your code is working for a smaller result set it's not correct - you need to capture the scroll_id returned in each new call to scroll() and use that for the next call.
python 广告滚动,使用python客户端弹性搜索滚动相关推荐
- python + selenium多进程爬取淘宝搜索页数据
python + selenium多进程爬取淘宝搜索页数据 1. 功能描述 按照给定的关键词,在淘宝搜索对应的产品,然后爬取搜索结果中产品的信息,包括:标题,价格,销量,产地等信息,存入mongodb ...
- python:imaplib --- IMAP4 协议客户端
python:imaplib --- IMAP4 协议客户端 简介 IMAP4 对象 IMAP4 示例 简介 本模块定义了三个类: IMAP4 . IMAP4_SSL 和 IMAP4_stream . ...
- 如何使用Python创建,读取,更新和搜索Excel文件
This article will show in detail how to work with Excel files and how to modify specific data with P ...
- Python 可视化近 90 天的百度搜索指数 + 词云图
作者 | 叶庭云 来源 | AI庭云君 一.简介 在实际业务中我们可能会使用爬虫根据关键词获取百度搜索指数历史数据,然后进行对应的数据分析. 百度指数,体验大数据之美.但要获取百度指数相关的数据,困难 ...
- python广告搞笑_技术入门 | 听说Python的广告刷爆了你的朋友圈?
前几天,一条 Python 广告刷爆了小编的朋友圈.网友纷纷惊呼,"什么鬼?居然这么多人在学 Python?"而在日前 IEEE Spectrum 发布的第五届年度编程语言交互排行 ...
- python zookeeper_ZooKeeper的安装以及客户端Kazoo(Python语言)的安装与使用
ZooKeeper具体的安装流程,如下所示: 首先,由于ZooKeeper是JAVA开发的,所以先要安装JDK,此处我是安装在/usr/local/jdk目录下,设置环境变量即可. 第二,到ZooKe ...
- pythondevp2p_以太坊GO、JAVA、PYTHON、RUBY、JS客户端介绍
原标题:以太坊GO.JAVA.PYTHON.RUBY.JS客户端介绍 区块链兄弟社区,区块链技术专业问答先行者,中国区块链技术爱好者聚集地 作者:佚名 来源:CSDN 原文链接:http://blog ...
- Python中的TCP的客户端UDP学习----第一篇博客
Python中的TCP的客户端&UDP学习--第一篇博客 PS: 每日的怼人句子"我真想把我的脑子放到你的身体里,让你感受一下智慧的光芒" 先说UDP流程 发送: 创建套接 ...
- python应用系列教程——python使用SocketServer实现网络服务器,socket实现客户端
全栈工程师开发手册 (作者:栾鹏) python教程全解 python使用SocketServer实现网络服务器 SocketServer简化了网络服务器的编写.在进行socket创建时,使用Sock ...
最新文章
- javascript控件(二):一个好用的表格(分页实例)
- 安装View Agent失败: The system must be rebooted before installation can continue
- 实现Javascript编写类的方式1(原生方式)
- 【转】对服务采购订单的条目确认
- TLS/SSl 相关攻击漏洞及检测方法(testssl.sh)
- 现代生活已经离不开的银行卡支付,背后原理其实没你想象的那么难!
- 理论基础 —— 队列 —— 链队列
- Linux的五个查找命令
- 强化学习在推荐混排中的应用
- iphone pageController 的实现
- 对话诸葛 io 孔淼:数据分析如何做,才能圈住用户?
- android audiotrack mp3,播放mp3数据压缩由JLayer和Audiotrack latin mp3在android
- Java基础 | 专业排行榜前7的Java代码审计工具
- Java 直接插入 CLOB/BLOB 数据到 Oracle 数据库
- 数值微分25 - Poisson 泊松方程(一维、二维):已知一些自定义的二阶导数点,得到一条曲线,即原方程平滑地通过它们)
- GBA火焰纹章改版-智慧的结晶
- 请用文言文写一篇500字的古文
- lumen model orm
- 《WinForm开发系列之控件篇》Item2 BindingNavigator
- HTML、CSS定义字体、颜色、背景等属性
热门文章
- centos升级内核 大漠知秋_记一次centos 7内核升级事故
- python爬取网页时返回http状态码HTTP Error 418以及如何查看自己的User-Agent
- idea开发搭建scala项目流程(二)
- 32 配置引脚中断_PCIe的中断机制
- java 交集怎么写_Java里面如何求两个集合的交集
- OpenShift 4 - 基于URL的应用路由
- 将Entity Framework Core v5.0移至单独的项目
- 将MongoDB.NET驱动程序与.NET Core WebAPI一起使用
- .NET Core 3.0中的新功能和增强功能
- 微软开源新字体 Cascadia Code,与 Terminal 一起开发