19092501es scroll-scan的python滚动翻页

本文介绍了一种利用Elasticsearch进行大规模数据检索的方法,通过设置特定的查询条件,实现对某一店铺所有商品信息的批量获取。示例代码展示了如何配置搜索参数、执行滚动搜索以及处理返回结果。
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

 

### 实现 `scroll-view` 组件中的横向滚动与元素定位 为了使 `scroll-view` 支持横向滚动,必须为其设定固定的宽度,并通过设置 `scroll-x="true"` 属性来启用该功能[^1]。对于想要实现平滑滚动至特定子节点的情况,则可以利用 `scroll-into-view` 属性配合目标节点的 ID 来达成目的。 下面是一个简单的例子展示如何配置这些属性: ```html <view class="container"> <!-- 设置 scroll-x=true 开启水平滚动 --> <scroll-view id="scrollView" scroll-x="true" bindscrolltolower="lower" lower-threshold="50" scroll-with-animation="{{true}}" scroll-left="{{currentLeft}}" style="width: 750rpx; white-space: nowrap;"> <!-- 子项列表 --> <block wx:for="{{items}}" wx:key="id"> <view id="{{item.id}}" class="child-item">{{item.text}}</view> </block> </scroll-view> </view> ``` 当需要让某个具体项目进入视图中央时,在 JavaScript 中更新对应的 `scroll-into-view` 值即可: ```javascript Page({ data: { currentId: '' }, scrollToItem(e) { const { id } = e.currentTarget.dataset; this.setData({ 'currentId': '#' + id }); } }) ``` 同时需要注意的是,如果希望在页面初次加载或者某些条件下自动滚到某位置,可以在合适时机调用 setData 方法改变 `scroll-into-view` 的值从而触发滚动行为。 另外,关于样式方面的问题,比如 Flexbox 不起作用的现象可能是由于容器本身没有足够的空间容纳所有子元素造成的;因此建议确保父级有足够的尺寸以适应内部内容的需求[^2]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值