File: searchable_snapshots.py

package info (click to toggle)
python-elasticsearch 7.17.6-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,276 kB
  • sloc: python: 23,010; makefile: 149
file content (164 lines) | stat: -rw-r--r-- 6,363 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#  Licensed to Elasticsearch B.V. under one or more contributor
#  license agreements. See the NOTICE file distributed with
#  this work for additional information regarding copyright
#  ownership. Elasticsearch B.V. licenses this file to you under
#  the Apache License, Version 2.0 (the "License"); you may
#  not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
# 	http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing,
#  software distributed under the License is distributed on an
#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#  KIND, either express or implied.  See the License for the
#  specific language governing permissions and limitations
#  under the License.

from .utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params


class SearchableSnapshotsClient(NamespacedClient):
    @query_params(
        "allow_no_indices",
        "expand_wildcards",
        "ignore_unavailable",
        response_mimetypes=["application/json"],
    )
    def clear_cache(self, index=None, params=None, headers=None):
        """
        Clear the cache of searchable snapshots.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/7.17/searchable-snapshots-apis.html>`_

        .. warning::

            This API is **experimental** so may include breaking changes
            or be removed in a future version

        :arg index: A comma-separated list of index names
        :arg allow_no_indices: Whether to ignore if a wildcard indices
            expression resolves into no concrete indices. (This includes `_all`
            string or when no indices have been specified)
        :arg expand_wildcards: Whether to expand wildcard expression to
            concrete indices that are open, closed or both.  Valid choices: open,
            closed, none, all  Default: open
        :arg ignore_unavailable: Whether specified concrete indices
            should be ignored when unavailable (missing or closed)
        """
        return self.transport.perform_request(
            "POST",
            _make_path(index, "_searchable_snapshots", "cache", "clear"),
            params=params,
            headers=headers,
        )

    @query_params(
        "master_timeout",
        "storage",
        "wait_for_completion",
        request_mimetypes=["application/json"],
        response_mimetypes=["application/json"],
    )
    def mount(self, repository, snapshot, body, params=None, headers=None):
        """
        Mount a snapshot as a searchable index.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/7.17/searchable-snapshots-api-mount-snapshot.html>`_

        :arg repository: The name of the repository containing the
            snapshot of the index to mount
        :arg snapshot: The name of the snapshot of the index to mount
        :arg body: The restore configuration for mounting the snapshot
            as searchable
        :arg master_timeout: Explicit operation timeout for connection
            to master node
        :arg storage: Selects the kind of local storage used to
            accelerate searches. Experimental, and defaults to `full_copy`
        :arg wait_for_completion: Should this request wait until the
            operation has completed before returning
        """
        for param in (repository, snapshot, body):
            if param in SKIP_IN_PATH:
                raise ValueError("Empty value passed for a required argument.")

        return self.transport.perform_request(
            "POST",
            _make_path("_snapshot", repository, snapshot, "_mount"),
            params=params,
            headers=headers,
            body=body,
        )

    @query_params(
        response_mimetypes=["application/json"],
    )
    def repository_stats(self, repository, params=None, headers=None):
        """
        DEPRECATED: This API is replaced by the Repositories Metering API.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/7.17/searchable-snapshots-apis.html>`_

        .. warning::

            This API is **experimental** so may include breaking changes
            or be removed in a future version

        :arg repository: The repository for which to get the stats for
        """
        if repository in SKIP_IN_PATH:
            raise ValueError("Empty value passed for a required argument 'repository'.")

        return self.transport.perform_request(
            "GET",
            _make_path("_snapshot", repository, "_stats"),
            params=params,
            headers=headers,
        )

    @query_params(
        "level",
        response_mimetypes=["application/json"],
    )
    def stats(self, index=None, params=None, headers=None):
        """
        Retrieve shard-level statistics about searchable snapshots.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/7.17/searchable-snapshots-apis.html>`_

        :arg index: A comma-separated list of index names
        :arg level: Return stats aggregated at cluster, index or shard
            level  Valid choices: cluster, indices, shards  Default: indices
        """
        return self.transport.perform_request(
            "GET",
            _make_path(index, "_searchable_snapshots", "stats"),
            params=params,
            headers=headers,
        )

    @query_params(
        response_mimetypes=["application/json"],
    )
    def cache_stats(self, node_id=None, params=None, headers=None):
        """
        Retrieve node-level cache statistics about searchable snapshots.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/7.17/searchable-snapshots-apis.html>`_

        .. warning::

            This API is **experimental** so may include breaking changes
            or be removed in a future version

        :arg node_id: A comma-separated list of node IDs or names to
            limit the returned information; use `_local` to return information from
            the node you're connecting to, leave empty to get information from all
            nodes
        """
        return self.transport.perform_request(
            "GET",
            _make_path("_searchable_snapshots", node_id, "cache", "stats"),
            params=params,
            headers=headers,
        )