2016-08-02 56 views
1

當前我正在使用以下程序從彈性搜索中提取id及其嚴重性信息。使用elasticsearch_dsl獲取所有行

from elasticsearch import Elasticsearch 
from elasticsearch_dsl import Search, Q 

client = Elasticsearch(
    [ 
     #'http://user:[email protected]:9200/', 
     'http://10.x.x.11:9200/', 
    ], 
    verify_certs=True 
) 

s = Search(using=client, index="test") 

response = s.execute() 

for hit in response: 
    print hit.message_id, hit.severity, "\n\n" 

我相信默認情況下查詢返回10行。我有超過10000行的彈性搜索。我需要獲取所有信息。

有人可以指導我如何運行相同的查詢來獲取所有記錄嗎?

回答

2

您可以爲了從您test索引檢索所有文檔使用scan() helper function

from elasticsearch import Elasticsearch, helpers 

client = Elasticsearch(
    [ 
     #'http://user:[email protected]:9200/', 
     'http://10.x.x.11:9200/', 
    ], 
    verify_certs=True 
) 

docs = list(helpers.scan(client, index="test", query={"query": {"match_all": {}}})) 

for hit in docs: 
    print hit.message_id, hit.severity, "\n\n" 
相關問題