主要是使用游标的方法,当前使用的ElasticSearch服务版本是5.6.14,python=3.7,elasticsearch(python库)=5.5.0。下面是可执行的分页代码。
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
@author:XXX
@time: 2019/4/28 16:39
@desc:
"""
import datetime
from typing import Callable
from elasticsearch import Elasticsearch, helpers
class ElasticSearchDao:
def __init__(self, hosts: list):
"""
初始化es客户端\n
:param hosts: 举例: hosts = ["10.10.10.1:9200", "10.10.10.12:9200", "10.10.10.3:9200"]
"""
self.es = Elasticsearch(hosts)
def get_cursor(self, index: str, doc_type: str, query: dict):
"""
获取游标\n
:param index: 索引名
:param doc_type: 文档类型
:param query: 查询语句
:return: 游标
"""
return helpers.scan