滚动弹性搜索,致电API并存储在弹性搜索异步中
我有一个弹性搜索索引(30GB,1M条目),我必须使用调用API(1S执行)更新每个文档,并对结果进行一些计算。
我尝试了很多事情,例如使用AioHTTP发送请求,与Asyncio创建一个队列,
唯一工作的是:
def search_and_store():
for i in range(1, count, CPU):
hits = es.search(index=['index'], size=CPU, from_=i)['hits']['hits']
data = [{"title": hit['_source']['name'], "body": hit['_source']['cleanText'],"id": hit["_id"]} for hit in
hits]
print(i)
with Pool(CPU) as p:
results = p.map(getresult_store, data)
p.close()
p.join()
def getresult_store(item):
body = ScoreManager.get_article_score(item['title'], item['body'])
elasticsearchManager.update_record(es, "searchdata", body, item['id'])
但是我确定有最好的方法可以做到这一点
I have a elastic search index (30GB, 1M entries), I have to update each document with calling an API (1s execution) and do some calculus on result.
I try many things like send request with aiohttp, create a Queue with asyncio, ect
The only things who work is that:
def search_and_store():
for i in range(1, count, CPU):
hits = es.search(index=['index'], size=CPU, from_=i)['hits']['hits']
data = [{"title": hit['_source']['name'], "body": hit['_source']['cleanText'],"id": hit["_id"]} for hit in
hits]
print(i)
with Pool(CPU) as p:
results = p.map(getresult_store, data)
p.close()
p.join()
def getresult_store(item):
body = ScoreManager.get_article_score(item['title'], item['body'])
elasticsearchManager.update_record(es, "searchdata", body, item['id'])
But I sure that there is a best way to do this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论