如何在我的索引下面生成在你的本地創(chuàng)建一個環(huán)境使用 pip 安裝必要的庫(elasticsearch、requests、requests_aws4auth、boto3)使用 lambda_function.py在里面創(chuàng)建文件env\Lib\site-packages\并添加以下代碼壓縮上述文件夾并將其命名為 lambda_function.zip 并上傳到 lambda 函數(shù),您可以在其中創(chuàng)建具有必要 IAM 角色的函數(shù)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])回復(fù)如下{"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"}}]}}如何將上述響應(yīng)保存為 s3 存儲桶中文件夾中的 json存儲桶名稱 = test20220elastic
如何將彈性搜索索引的響應(yīng)保存到 s3 存儲桶中
慕田峪4524236
2023-02-22 17:06:37