亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將彈性搜索索引的響應保存到 s3 存儲桶中

如何將彈性搜索索引的響應保存到 s3 存儲桶中

慕田峪4524236 2023-02-22 17:06:37
如何在我的索引下面生成在你的本地創建一個環境使用 pip 安裝必要的庫(elasticsearch、requests、requests_aws4auth、boto3)使用 lambda_function.py在里面創建文件env\Lib\site-packages\并添加以下代碼壓縮上述文件夾并將其命名為 lambda_function.zip 并上傳到 lambda 函數,您可以在其中創建具有必要 IAM 角色的函數import boto3 from requests_aws4auth import AWS4Auth from elasticsearch import Elasticsearch, RequestsHttpConnection session = boto3.session.Session() credentials = session.get_credentials() awsauth = AWS4Auth(credentials.access_key,                    credentials.secret_key,                    session.region_name, 'es',                    session_token=credentials.token) es = Elasticsearch(     ['https://search-testelastic-2276kyz2u4l3basec63onfq73a.us-east-1.es.amazonaws.com'],     http_auth=awsauth,     use_ssl=True,     verify_certs=True,     connection_class=RequestsHttpConnection ) def lambda_handler(event, context):     es.cluster.health()     es.indices.create(index='my-index', ignore=400)     r = [{'Name': 'Dr. Christopher DeSimone', 'Specialised and Location': 'Health'},  {'Name': 'Dr. Tajwar Aamir (Aamir)', 'Specialised and Location': 'Health'}]     for e in enumerate(r):          es.index(index="my-index", body=e[1])回復如下{"took":2,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":3,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"my-index_1","_type":"_doc","_id":"elqrJHMB10jKFvejVaNM","_score":1.0,"_source":{"Name":"Dr. Christopher DeSimone","Specialised and Location":"Health"}},{"_index":"my-index_1","_type":"_doc","_id":"e1qrJHMB10jKFvejVqMK","_score":1.0,"_source":{"Name":"Dr. Tajwar Aamir (Aamir)","Specialised and Location":"Health"}},{"_index":"my-index_1","_type":"_doc","_id":"fFqrJHMB10jKFvejVqMR","_score":1.0,"_source":{"Name":"Dr. Bernard M. Aaron","Specialised and Location":"Health"}}]}}如何將上述響應保存為 s3 存儲桶中文件夾中的 json存儲桶名稱 = test20220elastic
查看完整描述

1 回答

?
手掌心

TA貢獻1942條經驗 獲得超3個贊

您可以重用您的session對象來創建 S3 資源:


es = ...

s3 = session.resource('s3')

bucket = s3.Bucket('test20220elastic')


def lambda_handler(event, context):

    ...

    for e in enumerate(r):

        result = es.index(index="my-index", body=e[1])

        bucket.put_object(Body=json.dumps(result), Key="my_folder/my_result.json",

                          ContentType="application/json")

不過,您可能希望為每個結果建立一個不同的鍵名。


查看完整回答
反對 回復 2023-02-22
  • 1 回答
  • 0 關注
  • 132 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號