0

如何使用 pyes 获取随机文档?我有一个可以访问并想要探索的新集群

from pyes import *
conn = ES('127.0.0.1:9200', timeout=3.5)
#Now what?
4

1 回答 1

2

例如,您可以使用 and 匹配任何文档并MatchAllQuery返回一个随机文档。请注意,我任意选择创建一个随机数,但您可以更改此数字以更好地匹配索引中的文档数。start=xxxsize=11000

import random
from pyes import *
conn = ES('127.0.0.1:9200', timeout=3.5)

q = MatchAllQuery()
rnd = random.randint(1, 1000)     <-- 1000 depends on how many docs you have
docs = conn.search(Search(query=q, start=rnd, size=1))

random_doc = docs['hits']['hits'][0] <-- your random document
于 2015-07-20T03:51:54.507 回答