簡體   English   中英

ElasticSearch Scroll api問題

[英]ElasticSearch Scroll api issue

我試圖在Python中使用滾動API,我有一個問題,它循環我的整個數據集。

我得到大約100個結果,當它們應該超過150k時(我可以在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)

是因為你的電話是“return_es_results(res,100)”<---請注意你的電話中的100。

所以它循環到100 ...你只問100個結果!

你可能想要分頁? 如果你使用django,這里有一些關於分頁的文檔: https//docs.djangoproject.com/en/2.2/topics/pagination/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM