python elasticsearch scroll sca

2017-02-16  本文已影响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

上一篇下一篇

猜你喜欢

热点阅读