【问题标题】:ElasticSearch Scroll api issueElasticSearch Scroll api 问题
【发布时间】:2019-09-26 17:29:09
【问题描述】:

我正在尝试在 Python 中使用滚动 API,但它在我的整个数据集中循环时遇到了问题。

当应该有超过 150k 个结果时,我得到了大约 100 个返回结果(我可以在 kibana 中看到它们)

附上我的代码

res = helpers.scan(client = es, scroll = '2m', query = {
      "size": 10000,
        "query": {
          "match": {
            "type": {
              "query": "IP_Address"
            }}}}, 
    index = "logstash-*")

# function to return hits from the elasticsearch query in res

def get_es_json(es_scan):
    for hits in es_scan:
        return hits

# iterate through results with defined number of results

def return_es_results(es_json_data, num_results):
    for i in range(num_results):
        data = get_es_json(es_json_data)
        print(data['_source']['geoip']['asn'])

return_es_results(res, 100)

【问题讨论】:

    标签: python json api elasticsearch scroll


    【解决方案1】:

    是不是因为您的电话是“return_es_results(res, 100)”

    所以它会循环直到 100...您只询问 100 个结果!

    您可能想要分页? 如果你使用 django,这里有一些关于分页的文档: https://docs.djangoproject.com/en/2.2/topics/pagination/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-24
      • 1970-01-01
      相关资源
      最近更新 更多