欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

#在python3上運(yùn)行
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ù)字序列的時(shí)候,
  # 用xrange會(huì)比range性能優(yōu)很多,
  # 因?yàn)椴恍枰簧蟻砭烷_辟一塊很大的內(nèi)存空間。
  # x = range(0,10);type(x) 是一個(gè)列表
  # x1 = xrange(0,10);type(x1) 是一個(gè)生成器 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 實(shí)現(xiàn)分頁顯示從es中獲取的數(shù)據(jù)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論