Skip to content

Commit ba234dc

Browse files
committed
Allow access to xpack methods without .xpack
1 parent 7785dd1 commit ba234dc

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

elasticsearch/client/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .remote import RemoteClient
1313
from .snapshot import SnapshotClient
1414
from .tasks import TasksClient
15-
from .xpack import XPackClient
15+
from .xpack import XPackClient, XPACK_NAMESPACES
1616
from .utils import query_params, _make_path, SKIP_IN_PATH
1717

1818
logger = logging.getLogger("elasticsearch")
@@ -214,6 +214,12 @@ def __init__(self, hosts=None, transport_class=Transport, **kwargs):
214214
self.remote = RemoteClient(self)
215215
self.snapshot = SnapshotClient(self)
216216
self.tasks = TasksClient(self)
217+
218+
# new style access to x-pack features without .xpack step
219+
for namespace, NamespacedClient in XPACK_NAMESPACES.items():
220+
setattr(self, namespace, NamespacedClient(self))
221+
222+
# old style xpack access
217223
self.xpack = XPackClient(self)
218224

219225
def __repr__(self):

elasticsearch/client/xpack/__init__.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,30 @@
1616
from .ssl import SslClient
1717
from .watcher import WatcherClient
1818

19+
XPACK_NAMESPACES = {
20+
"ccr": CcrClient,
21+
"data_frame": Data_FrameClient,
22+
"deprecation": DeprecationClient,
23+
"graph": GraphClient,
24+
"ilm": IlmClient,
25+
"indices": IndicesClient,
26+
"license": LicenseClient,
27+
"migration": MigrationClient,
28+
"ml": MlClient,
29+
"monitoring": MonitoringClient,
30+
"rollup": RollupClient,
31+
"security": SecurityClient,
32+
"sql": SqlClient,
33+
"ssl": SslClient,
34+
"watcher": WatcherClient,
35+
}
1936

2037
class XPackClient(NamespacedClient):
21-
namespace = "xpack"
22-
2338
def __init__(self, *args, **kwargs):
2439
super(XPackClient, self).__init__(*args, **kwargs)
25-
self.ccr = CcrClient(self.client)
26-
self.data_frame = Data_FrameClient(self.client)
27-
self.deprecation = DeprecationClient(self.client)
28-
self.graph = GraphClient(self.client)
29-
self.ilm = IlmClient(self.client)
30-
self.indices = IndicesClient(self.client)
31-
self.license = LicenseClient(self.client)
32-
self.migration = MigrationClient(self.client)
33-
self.ml = MlClient(self.client)
34-
self.monitoring = MonitoringClient(self.client)
35-
self.rollup = RollupClient(self.client)
36-
self.security = SecurityClient(self.client)
37-
self.sql = SqlClient(self.client)
38-
self.ssl = SslClient(self.client)
39-
self.watcher = WatcherClient(self.client)
40+
41+
for namespace in XPACK_NAMESPACES:
42+
setattr(self, namespace, getattr(self.client, namespace))
4043

4144
@query_params("categories", "human")
4245
def info(self, params=None):

0 commit comments

Comments
 (0)