Elasticsearch分页查询
global index
global CLIENT
index = "guajibao-ipused-2019.10.13"
CLIENT = Elasticsearch(hosts=es_host,port=port,timeout=timeout) def load_all_data(scroll_id):
if scroll_id:
page = CLIENT.scroll(scroll_id=scroll_id, scroll='10m')
scroll_id = page['_scroll_id']
else:
page = CLIENT.search(index=index, scroll='10m', size=100)
scroll_id = page['_scroll_id']
print(page)
data = page["hits"]['hits']
return {"data": data, "scroll_id": scroll_id, "length": len(data)} 例子 def load_all_data(scroll_id):
if scroll_id:
page = CLIENT.scroll(scroll_id=scroll_id, scroll='10m')
scroll_id = page['_scroll_id']
else:
page = CLIENT.search(index=index, scroll='10m', size=100)
scroll_id = page['_scroll_id']
# print(page)
data = page["hits"]['hits']
total = page['hits']['total']['value']
print(data)
return {"data": data, "scroll_id": scroll_id, "length": len(data), "total": total} if __name__ == "__main__":
result = load_all_data(None)
total = result['total']
scroll_id = result['scroll_id']
for i in range(int(total/100)):
scroll_id = load_all_data(scroll_id)['scroll_id']
global index
global CLIENT
index = "guajibao-ipused-2019.10.13"
CLIENT = Elasticsearch(hosts=es_host,port=port,timeout=timeout)
def load_all_data(scroll_id):
if scroll_id:
page = CLIENT.scroll(scroll_id=scroll_id, scroll='10m')
scroll_id = page['_scroll_id']
else:
page = CLIENT.search(index=index, scroll='10m', size=100)
scroll_id = page['_scroll_id']
print(page)
data = page["hits"]['hits']
return {"data": data, "scroll_id": scroll_id, "length": len(data)}
例子
def load_all_data(scroll_id):
if scroll_id:
page = CLIENT.scroll(scroll_id=scroll_id, scroll='10m')
scroll_id = page['_scroll_id']
else:
page = CLIENT.search(index=index, scroll='10m', size=100)
scroll_id = page['_scroll_id']
# print(page)
data = page["hits"]['hits']
total = page['hits']['total']['value']
print(data)
return {"data": data, "scroll_id": scroll_id, "length": len(data), "total": total}
if __name__ == "__main__":
result = load_all_data(None)
total = result['total']
scroll_id = result['scroll_id']
for i in range(int(total/100)):
scroll_id = load_all_data(scroll_id)['scroll_id']
Elasticsearch分页查询的更多相关文章
- elasticsearch 分页查询实现方案——Top K+归并排序
elasticsearch 分页查询实现方案 1. from+size 实现分页 from表示从第几行开始,size表示查询多少条文档.from默认为0,size默认为10,注意:size的大小不能超 ...
- Elasticsearch——分页查询From&Size VS scroll
Elasticsearch中数据都存储在分片中,当执行搜索时每个分片独立搜索后,数据再经过整合返回.那么,如果要实现分页查询该怎么办呢? 更多内容参考Elasticsearch资料汇总 按照一般的查询 ...
- ElasticSearch—分页查询
ElasticSearch查询—分页查询详解 Elasticsearch中数据都存储在分片中,当执行搜索时每个分片独立搜索后,数据再经过整合返回.那么,如何实现分页查询呢? 按照一般的查询流程来说,如 ...
- elasticsearch 分页查询实现方案
1. from+size 实现分页 from表示从第几行开始,size表示查询多少条文档.from默认为0,size默认为10, 注意:size的大小不能超过index.max_result_wind ...
- ElasticSearch——分页查询
前言 ElasticSearch实现分页查询,有3种方式,他们在数据查询中各自占据着不同的优势,因此在搜索引擎的数据分页过程中,如何更好地利用各自的优势来进行数据查询是一个非常重要的过程. 传统分页( ...
- Elasticsearch 分页查询
目录 前言 from + size search after scroll api 总结 参考资料 前言 我们在实际工作中,有很多分页的需求,商品分页.订单分页等,在MySQL中我们可以使用limit ...
- Elasticsearch教程(九) elasticsearch 查询数据 | 分页查询
Elasticsearch 的查询很灵活,并且有Filter,有分组功能,还有ScriptFilter等等,所以很强大.下面上代码: 一个简单的查询,返回一个List<对象> .. ...
- elasticsearch查询之大数据集分页查询
一. 要解决的问题 search命中的记录特别多,使用from+size分页,直接触发了elasticsearch的max_result_window的最大值: { "error" ...
- Elasticsearch from/size-浅分页查询-深分页 scroll-深分页search_after深度查询区别使用及应用场景
Elasticsearch调研深度查询 1.from/size 浅分页查询 一般的分页需求我们可以使用from和size的方式实现,但是这种的分页方式在深分页的场景下应该是避免使用的.深分页的页次增加 ...
随机推荐
- 01-Verilog基本语法元素
不知道能不能更新完,毕竟咱学校计院对硬件向来不太重视,现在对竞赛也不咋地重视了,也不加分,也没啥用.嘛,就随便写写玩玩吧. 一只狸无聊的时候对Verilog的业余描述笔记:以<Verilog数字 ...
- w1R3s靶机work_through
前言 这靶机挺简单的.虽然网友们有分享oscp向的靶机集,但是没有一个难度梯度,做起来就怪怪的. 打点 nmap -sP 192.168.218.0/24 发现主机IP 192.168.218.134 ...
- Laravel打印sql日志
直接打印 use Log; use DB; DB::connection()->enableQueryLog(); Log::info(DB::getQueryLog()); //print_r ...
- 通过中转DLL函数实现DLL劫持
当我们运行程序时,一般情况下会默认加载Ntdll.dll和Kernel32.dll这两个链接库,在进程未被创建之前Ntdll.dll库就被默认加载了,三环下任何对其劫持都是无效的,除了该Dll外,其他 ...
- 路由器逆向分析------MIPS交叉编译环境的搭建(Buildroot)
本文博客地址:http://blog.csdn.net/qq1084283172/article/details/68950682 为了能在我们熟悉的windows或者ubuntu下开发mips架构的 ...
- hdu4915 判断括号匹配
题意: 问你括号匹配是否唯一,三种字符'(','?',')',问号可以变成任何字符. 思路: 首先我们要学会判断当前串是否成立?怎么判断?我的方法是跑两遍,开三个变变量 s1 ...
- POJ2349二分+并查集,类似最小树的贪心
题意: 给你n个点,你的任务是构建一颗通讯树,然后给你一个s表示可以选出来s个点两两通讯不花钱,就是费用是0,其他的费用就是两点的距离,有个要求就是其他的费用中最大的那个最小. 思路: ...
- LeetCode---84. 柱状图中最大的矩形(hard)
题目:84. 柱状图中最大的矩形 给定 n 个非负整数,用来表示柱状图中各个柱子的高度.每个柱子彼此相邻,且宽度为 1 . 求在该柱状图中,能够勾勒出来的矩形的最大面积. 示例: 输入: [2,1,5 ...
- HDU - 2091 空心三角形 水题,但是有点坑...
空心三角形 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- Promise解析(待完成)
Promise是一种异步操作的解决方案,将写法复杂的传统的回调函数和监听事件的异步操作,用同步代码的形式表达出来.避免了多级异步操作的回调函数嵌套. 1.主要用于异步计算 2.可以将异步操作队列化,按 ...