一.下載依賴模塊
# pip3 install elasticsearch elasticsearch-xpack
二.實例代碼
#!/usr/bin/python3
#--coding:utf-8--
from elasticsearch import Elasticsearch
from elasticsearch_xpack import LicenseClient
es = Elasticsearch(
['IP_HOST:9200'],
http_auth=('用戶名','密碼')
)
xpack = LicenseClient(es)
print(xpack.get())
ps:過程中網上的方法不全,還是需要通過查詢模塊的用法結合模塊源碼來編寫方法
>>> import elasticsearch
>>> print(dir(elasticsearch))
['AuthenticationException', 'AuthorizationException', 'ConflictError', 'Connection', 'ConnectionError', 'ConnectionPool', 'ConnectionSelector', 'ConnectionTimeout', 'Elasticsearch', 'ElasticsearchException', 'ImproperlyConfigured', 'JSONSerializer', 'NotFoundError', 'NullHandler', 'RequestError', 'RequestsHttpConnection', 'RoundRobinSelector', 'SSLError', 'SerializationError', 'Transport', 'TransportError', 'Urllib3HttpConnection', 'VERSION', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '__versionstr__', 'absolute_import', 'client', 'compat', 'connection', 'connection_pool', 'exceptions', 'logger', 'logging', 'serializer', 'sys', 'transport']
>>> from elasticsearch_xpack import XPackClient
>>> print(dir(XPackClient))
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'infect_client', 'info', 'namespace', 'transport', 'usage']
>>> import elasticsearch_xpack
>>> print(dir(elasticsearch_xpack))
['AddonClient', 'DeprecationClient', 'GraphClient', 'LicenseClient', 'MigrationClient', 'MlClient', 'MonitoringClient', 'SecurityClient', 'WatcherClient', 'XPackClient', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'deprecation', 'graph', 'license', 'migration', 'ml', 'monitoring', 'query_params', 'security', 'watcher']
>>> print(dir(elasticsearch_xpack.LicenseClient))
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'delete', 'get', 'post', 'transport']