python Elasticsearch scroll 分页

https://www.jianshu.com/p/6f873488124c

 

# -*- coding: utf-8 -*-
import datetime

import cv2
from elasticsearch import Elasticsearch
es = Elasticsearch(['192.168.55.90:9200'])

source_arr = ["uri",#"coordinateList.height",
                  "camera.deviceId",
                  "photo.capturenum",
                  "fileName","flag","captureInfo.currentDistinguishNum"]
page = es.search(
    index="ccat1", doc_type='demo0',
    scroll ='2m',
    # search_type ='scan',
    size =10000,
    body={"_source": source_arr,"query":  {"bool": {
       "must": [
           # {"match": {"camera.deviceId.keyword": "e521da68922f470a9af492b34fd89b6e"}},
           # {"match": {"captureInfo.currentDistinguishNum": 0}},
           {"range": {
                   "photo.capturenum": {
                       "gte": 1,
                       "lte": 10
                   }
               }
           },
           {"range": {
               "ymdh": {
                   "gte": 2018062300,
                   "lte": 2018072317
               }
           }
           }
       ]}
       }}

)

sid = page['_scroll_id']
scroll_size = page['hits']['total']

print()
# Start scrolling
while(scroll_size > 0):
    time1=datetime.datetime.now()
    page = es.scroll(scroll_id=sid, scroll='2m')
    # Update the scroll ID
    sid = page['_scroll_id']
    # Get the number of results that we returned in the last scroll
    scroll_size = len(page['hits']['hits'])
    print("scroll size: " + str(scroll_size),(datetime.datetime.now()-time1).microseconds)
# Do something with the obtained page
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值