欢迎投稿

今日深度:

python使用Elasticsearch库下载索引数据,

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))

www.htsjk.Com true http://www.htsjk.com/Elasticsearch/29456.html NewsArticle python使用Elasticsearch库下载索引数据, from elasticsearch import Elasticsearches = Elasticsearch ( hosts = [ { 'host' : 'localhost' , 'port' : 9210 } ] ) dealnum = 0 if __name__ == '__main__' : #查询条件 es_search_options = {...
相关文章
    暂无相关文章
评论暂时关闭