request使用用户名密码访问Openseacrh


Python 使用用户名密码访问Openseacrh

import requests
import json
opensearch_url = "https://xxx.cn-north-1.es.amazonaws.com.cn"

headers = {
    "Content-Type": "application/json"
}
auth = ('username',   'password')
# 创建或更新索引(如果不存在)


for i in range(1000):
    index_name = f"ism{i}"
    response = requests.put(f"{opensearch_url}/{index_name}", headers=headers, auth=auth)
    print(response.text)
    # 写入单条数据
    doc = {
        "name": "John Doe",
        "age": 30,
        "job": "Engineer"
    }
    response = requests.post(f"{opensearch_url}/{index_name}/_doc", headers=headers, data=json.dumps(doc), auth=auth)
    print(response.text)

文章作者: AWS Learner
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 AWS Learner !
评论
  目录