ElasticsearchPythonHook¶
使用原生 Python 客户端与 Elasticsearch 通信的 Elasticsearch 挂钩
参数¶
- hosts
单个或多个 Elasticsearch 实例的列表。示例:
["https://127.0.0.1:9200"]
。- es_conn_args
连接到 Elasticsearch 可能需要的其他参数。示例:
{"ca_cert":"/path/to/cert", "basic_auth": "(user, pass)"}
有关所有可能的配置,请参阅 Elasticsearch 文档。参考: https://elastic.ac.cn/guide/en/elasticsearch/client/python-api/current/connecting.html
使用示例¶
def use_elasticsearch_hook():
"""
Use ElasticSearchPythonHook to print results from a local Elasticsearch
"""
es_hosts = ["https://127.0.0.1:9200"]
es_hook = ElasticsearchPythonHook(hosts=es_hosts)
query = {"query": {"match_all": {}}}
result = es_hook.search(query=query)
print(result)
return True