【问题标题】:Fetch all the rows using elasticsearch_dsl使用 elasticsearch_dsl 获取所有行
【发布时间】:2016-12-07 17:35:34
【问题描述】:

目前我正在使用以下程序从弹性搜索中提取 id 及其严重性信息。

from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search, Q

client = Elasticsearch(
    [
        #'http://user:secret@10.x.x.11: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 行。我需要获取所有信息。

谁能指导我如何运行相同的查询来获取所有记录?

【问题讨论】:

    标签: elasticsearch elasticsearch-dsl


    【解决方案1】:

    您可以使用scan() helper function 来检索您的test 索引中的所有文档:

    from elasticsearch import Elasticsearch, helpers
    
    client = Elasticsearch(
        [
            #'http://user:secret@10.x.x.11: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"
    

    【讨论】:

      猜你喜欢
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-04
      • 1970-01-01
      相关资源
      最近更新 更多