我希望通过 elasticsearch python 框架找到我的问题的答案。也许我完全失明或做错了什么,但我现在很困惑,找不到合适的答案。
我目前正在尝试使用elasticsearch python 框架建立到我的弹性搜索 API 的连接,我的代码如下所示:
from elasticsearch import Elasticsearch
def create_es_connection(host: str, port: int, api_key_id: str, api_key: str, user: str, pw: str) -> Elasticsearch:
return Elasticsearch([f"https://{user}:{pw}@{host}:{port}"])
Run Code Online (Sandbox Code Playgroud)
这工作正常。然后我为我的testuser创建了一个 API 密钥,我也将它提供给了上面的函数。我现在正在尝试做类似的事情:Elasticsearch([f"https://{api_key_id}:{api_key}@{host}:{port}"])所以,我想完全省略用户和密码,因为关于这个片段背后的更大项目,我在保存用户/密码凭据时感觉不太好我的项目(甚至可能将其推送到我们的 git 服务器)。迟早,这些凭据必须在某个地方输入,我认为只保存 API 密钥并使用它进行身份验证可能更安全。不幸的是,这并没有像我计划的那样成功,我找不到任何关于如何仅使用 API 密钥进行身份验证的信息。
我究竟做错了什么?事实上,我对此知之甚少,以至于我在这里质疑我的基本理解。谢谢您的回复!