gpt4 book ai didi

elasticsearch - 使用elasticsearch_dsl获取所有行

转载 作者:行者123 更新时间:2023-12-03 00:04:52 29 4
gpt4 key购买 nike

目前,我正在使用以下程序从 flex 搜索中提取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行。我在 flex 搜索中有超过10000行。我需要获取所有信息。

有人可以指导我如何运行同一查询以获取所有记录吗?

最佳答案

您可以使用 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"

关于elasticsearch - 使用elasticsearch_dsl获取所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45791269/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com