程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python3 操作Elasticsearch,獲取xpack的license信息

編輯:Python

一.下載依賴模塊

# 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']

 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved