elasticsearch scroll

最开始接触E的版本是2.3.4,随着功能和版本更新,现在已更新到7.10.2,但是在导出数据的时候遇到了一个小问题

之前记得scroll,但是操作的是总是第一次成功,后面拿到scroll_id的第二次后就无法继续读取数据了,

最后排查发现是自己疏忽了用法

第一次:

    host = "*******"
    port = 9200
    es_index = "hts2840"
    es_type = "index"
    es_connect_url = "{0}:{1}/{2}/{3}/_search?scroll=60s".format(
        host, port, es_index, es_type)

第n+1次:

            # scroll第n+1次的时候,不需要索引和type了
            scroll_url = "{0}:{1}/_search/scroll".format(
                host, port)
            scroll_json = {
                "scroll": dealy_time,
                "scroll_id": scroll_id
            }        

  第一次请求以后的地址不需要index了,只需要带着scroll_id即可,小小的失误耽误了快1个小时

原文地址:https://www.cnblogs.com/fly-kaka/p/14688528.html