美文网首页
python elasticsearch scroll sca

python elasticsearch scroll sca

作者: 阳春是你 | 来源:发表于2017-02-16 17:20 被阅读2479次
    from elasticsearch import Elasticsearch
    es = Elasticsearch([
            'http://conf:9200/'
        ])
    page = es.search(
        index ='ware_index',
        doc_type ='ware_type',
        scroll ='2m',
        search_type ='scan',
        size =1000,
        body ={
            "query":{
                "match_all":{}
            },
            "filter":{
                "term":{
                    "shop":"230"
                }
            }
        }
    )
    
    sid = page['_scroll_id']
    scroll_size = page['hits']['total']
     
    # Start scrolling
    while(scroll_size >0):
        print "Scrolling..."
        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)
        # Do something with the obtained page
    
    

    相关文章

      网友评论

          本文标题: python elasticsearch scroll sca

          本文链接:https://www.haomeiwen.com/subject/aglhwttx.html