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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
|
# 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.
import typing as t
from elastic_transport import ObjectApiResponse
from ._base import NamespacedClient
from .utils import (
SKIP_IN_PATH,
Stability,
_quote,
_rewrite_parameters,
_stability_warning,
)
class SearchableSnapshotsClient(NamespacedClient):
@_rewrite_parameters()
@_stability_warning(Stability.EXPERIMENTAL)
async def cache_stats(
self,
*,
node_id: t.Optional[t.Union[str, t.Sequence[str]]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
master_timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get cache statistics.
Get statistics about the shared cache for partially mounted indices.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-searchable-snapshots-cache-stats>`_
:param node_id: The names of the nodes in the cluster to target.
:param master_timeout:
"""
__path_parts: t.Dict[str, str]
if node_id not in SKIP_IN_PATH:
__path_parts = {"node_id": _quote(node_id)}
__path = f'/_searchable_snapshots/{__path_parts["node_id"]}/cache/stats'
else:
__path_parts = {}
__path = "/_searchable_snapshots/cache/stats"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if master_timeout is not None:
__query["master_timeout"] = master_timeout
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="searchable_snapshots.cache_stats",
path_parts=__path_parts,
)
@_rewrite_parameters()
@_stability_warning(Stability.EXPERIMENTAL)
async def clear_cache(
self,
*,
index: t.Optional[t.Union[str, t.Sequence[str]]] = None,
allow_no_indices: t.Optional[bool] = None,
error_trace: t.Optional[bool] = None,
expand_wildcards: t.Optional[
t.Union[
t.Sequence[
t.Union[str, t.Literal["all", "closed", "hidden", "none", "open"]]
],
t.Union[str, t.Literal["all", "closed", "hidden", "none", "open"]],
]
] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
ignore_unavailable: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Clear the cache.
Clear indices and data streams from the shared cache for partially mounted indices.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-searchable-snapshots-clear-cache>`_
:param index: A comma-separated list of data streams, indices, and aliases to
clear from the cache. It supports wildcards (`*`).
:param 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)
:param expand_wildcards: Whether to expand wildcard expression to concrete indices
that are open, closed or both.
:param ignore_unavailable: Whether specified concrete indices should be ignored
when unavailable (missing or closed)
"""
__path_parts: t.Dict[str, str]
if index not in SKIP_IN_PATH:
__path_parts = {"index": _quote(index)}
__path = f'/{__path_parts["index"]}/_searchable_snapshots/cache/clear'
else:
__path_parts = {}
__path = "/_searchable_snapshots/cache/clear"
__query: t.Dict[str, t.Any] = {}
if allow_no_indices is not None:
__query["allow_no_indices"] = allow_no_indices
if error_trace is not None:
__query["error_trace"] = error_trace
if expand_wildcards is not None:
__query["expand_wildcards"] = expand_wildcards
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if ignore_unavailable is not None:
__query["ignore_unavailable"] = ignore_unavailable
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
endpoint_id="searchable_snapshots.clear_cache",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=(
"index",
"ignore_index_settings",
"index_settings",
"renamed_index",
),
)
async def mount(
self,
*,
repository: str,
snapshot: str,
index: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
ignore_index_settings: t.Optional[t.Sequence[str]] = None,
index_settings: t.Optional[t.Mapping[str, t.Any]] = None,
master_timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
pretty: t.Optional[bool] = None,
renamed_index: t.Optional[str] = None,
storage: t.Optional[str] = None,
wait_for_completion: t.Optional[bool] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Mount a snapshot.
Mount a snapshot as a searchable snapshot index.
Do not use this API for snapshots managed by index lifecycle management (ILM).
Manually mounting ILM-managed snapshots can interfere with ILM processes.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-searchable-snapshots-mount>`_
:param repository: The name of the repository containing the snapshot of the
index to mount.
:param snapshot: The name of the snapshot of the index to mount.
:param index: The name of the index contained in the snapshot whose data is to
be mounted. If no `renamed_index` is specified, this name will also be used
to create the new index.
:param ignore_index_settings: The names of settings that should be removed from
the index when it is mounted.
:param index_settings: The settings that should be added to the index when it
is mounted.
:param master_timeout: The period to wait for the master node. If the master
node is not available before the timeout expires, the request fails and returns
an error. To indicate that the request should never timeout, set it to `-1`.
:param renamed_index: The name of the index that will be created.
:param storage: The mount option for the searchable snapshot index.
:param wait_for_completion: If true, the request blocks until the operation is
complete.
"""
if repository in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'repository'")
if snapshot in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'snapshot'")
if index is None and body is None:
raise ValueError("Empty value passed for parameter 'index'")
__path_parts: t.Dict[str, str] = {
"repository": _quote(repository),
"snapshot": _quote(snapshot),
}
__path = (
f'/_snapshot/{__path_parts["repository"]}/{__path_parts["snapshot"]}/_mount'
)
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if master_timeout is not None:
__query["master_timeout"] = master_timeout
if pretty is not None:
__query["pretty"] = pretty
if storage is not None:
__query["storage"] = storage
if wait_for_completion is not None:
__query["wait_for_completion"] = wait_for_completion
if not __body:
if index is not None:
__body["index"] = index
if ignore_index_settings is not None:
__body["ignore_index_settings"] = ignore_index_settings
if index_settings is not None:
__body["index_settings"] = index_settings
if renamed_index is not None:
__body["renamed_index"] = renamed_index
__headers = {"accept": "application/json", "content-type": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="searchable_snapshots.mount",
path_parts=__path_parts,
)
@_rewrite_parameters()
async def stats(
self,
*,
index: t.Optional[t.Union[str, t.Sequence[str]]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
level: t.Optional[
t.Union[str, t.Literal["cluster", "indices", "shards"]]
] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get searchable snapshot statistics.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-searchable-snapshots-stats>`_
:param index: A comma-separated list of data streams and indices to retrieve
statistics for.
:param level: Return stats aggregated at cluster, index or shard level
"""
__path_parts: t.Dict[str, str]
if index not in SKIP_IN_PATH:
__path_parts = {"index": _quote(index)}
__path = f'/{__path_parts["index"]}/_searchable_snapshots/stats'
else:
__path_parts = {}
__path = "/_searchable_snapshots/stats"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if level is not None:
__query["level"] = level
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="searchable_snapshots.stats",
path_parts=__path_parts,
)
|