滚动弹性搜索,致电API并存储在弹性搜索异步中

发布于 2025-01-23 04:37:49 字数 764 浏览 1 评论 0原文

我有一个弹性搜索索引(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文