首页 > 编程语言 >python 读取elasticsearch数据

python 读取elasticsearch数据

时间:2023-01-13 10:02:30浏览次数:36  
标签:hits 读取 python page elasticsearch id total scroll es


from elasticsearch import Elasticsearch


es = Elasticsearch(['x.x.x.x'], timeout=36000)

body1 = {"size": 10000,
"query": {"match_all": {}}}

res1 = es.search(index="goods",scroll='5m', body=body1)


print('#############################################3')
# print(count)

es_size = 1000
page=res1
total_hits=page['hits']['total'] # total es requests for this query - int
total_requests=int(total_hits['value']/es_size +1) # int
es_scroll_id = page['_scroll_id'] # first es return index - string
es_result=page['hits']['hits'] #first es return context

for i in range(0, total_requests):
page_scroll=es.scroll(scroll_id=es_scroll_id, scroll='30s')['hits']['hits']
print(page_scroll)
es_result += page_scroll


标签:hits,读取,python,page,elasticsearch,id,total,scroll,es
From: https://blog.51cto.com/u_15202985/6005786

相关文章

  • fs模块读取文件内容
         ......
  • 【Python爬虫项目实战】Python爬虫豆瓣Top250电影短评数据保存本地
    前言今天给大家介绍的是Python爬虫豆瓣Top250电影短评数据保存本地,在这里给需要的小伙伴们帮助,并且给出一点小心得。开发工具Python版本:3.6相关模块:requests模块par......
  • python 检测指定文件夹的大小及文件数量
    importosdefget_size(start_path='.'):total_size=0fordirpath,dirnames,filenamesinos.walk(start_path):forfinfilenames:......
  • abseil python命令库总结
    absl(AbseilPythonCommonLibraries)(https://abseil.io/docs/python/)是用于构建Python应用程序的Python库代码集合,它包括三个子库:app,flags,logging。appapp是Absei......
  • python django校园二手商城
    pythondjango校园二手商城 django二手商城django校园商城django校园商店django电子商城django网上商城前端:htmlcss等后端:pythondjango数据库:MYSQL涉及功能......
  • python Django垃圾分类系统
    pythonDjango垃圾分类系统 pythonDjango垃圾回收系统python校园垃圾分类系统后端:python3.7+Django3.2前端:html js css等数据库:MySQL功能:注册、登录、修改......
  • Python路面平整度检测车辆数据——速度修正
    全文链接:http://tecdat.cn/?p=31268原文出处:拓端数据部落公众号分析师:BohaoZhan目前主流的轻量化路面平整度检测技术方案为:使用车载加速度传感器采集车辆在路面上行驶......
  • Pycharm中没有显示miniconda刚创建好的Python2.7的测试环境
    目录​​前言​​​​问题描述​​​​解决​​​​结语​​前言Hello!非常感谢您阅读海轰的文章,倘若文中有错误的地方,欢迎您指出~ 自我介绍ଘ(੭ˊᵕˋ)੭昵称:海轰标......
  • python代码如何打包成exe文件
    引言:有时候,别人使用我们代码的时候,不太会安装所需要的IDE或者本地没有IDE(环境),这时候就需要将我们的代码打包成不依赖于外界环境的可执行程序,即.exe文件。那么,该如何将Pyth......
  • Python实现希尔排序、快速排序、归并排序
    快速排序快速排序(英语:Quicksort),又称划分交换排序(partition-exchangesort),通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都......