亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python 實現(xiàn)分頁顯示從es中獲取的數(shù)據(jù)方法

 更新時間:2018年12月26日 15:28:24   作者:sxf_0123  
今天小編就為大家分享一篇python 實現(xiàn)分頁顯示從es中獲取的數(shù)據(jù)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

注意:使用該方法,獲取的數(shù)據(jù)總數(shù)目不能超過1萬,否則出錯

#在python3上運行
from elasticsearch import Elasticsearch
from urllib3.connectionpool import xrange

def get_page_data(result):
  for hit in result['hits']['hits']:
    print(hit)

if __name__=='__main__':
  es_host = "0.0.0.0"
  port = 9200
  timeout = 15000
  index = "gather-v10"
  es = Elasticsearch(hosts=es_host,port=port,timeout=timeout)
  # gather-v10 總條數(shù)
  count = es.count(index=index)['count']
  # 每頁顯示條數(shù)
  page_line = 2
  #顯示多少頁
  if (count%page_line==0):
    page = (int)(count/page_line)
  else:
    page = (int)(count/page_line+1)
  # 要生成很大的數(shù)字序列的時候,
  # 用xrange會比range性能優(yōu)很多,
  # 因為不需要一上來就開辟一塊很大的內(nèi)存空間。
  # x = range(0,10);type(x) 是一個列表
  # x1 = xrange(0,10);type(x1) 是一個生成器 xrange(0,10)
  for x in xrange(0,page):
    rs = es.search(index=index,body={
      "query":{
        "match_all":{}
      },
      "from":x*page_line,
      "size":page_line
    })
    get_page_data(rs)

以上這篇python 實現(xiàn)分頁顯示從es中獲取的數(shù)據(jù)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論