python使用Elasticsearch库下载索引数据,
from elasticsearch import Elasticsearch
es= Elasticsearch(hosts=[{'host': 'localhost', 'port': 9210}])
dealnum=0
if __name__=='__main__':
#查询条件
es_search_options = {'query': {'match_all': {}}}
#查询的索引名称
es_index='dns_2018_09_26_ipdomainrelation'
#查询的文档名称
es_type='br2004'
#翻页查询
resp =es.search(es_index,es_type,body=es_search_options,scroll="1m",size=100)
print(len(resp['hits']['hits']))
scroll_id = resp['_scroll_id']
resp_docs = resp["hits"]["hits"]
total = resp['hits']['total']
count = len(resp_docs)
datas = resp_docs
print("total:"+str(total))
print(scroll_id)
#循环翻页查询
while len(resp_docs)>0:
scroll_id=resp['_scroll_id']
#对于版本1.0的es,scroll_id和body一定都要传,否则会出错
resp = es.scroll(scroll_id=scroll_id, body={'scroll_id':scroll_id},scroll="1m")
resp_docs = resp["hits"]["hits"]
datas.extend(resp_docs)
count += len(resp_docs)
dealnum += 1
print("dealnum::=="+str(dealnum))
if count >= total:
break
print(len(datas))
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。