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 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233
|
# 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 HeadApiResponse, ObjectApiResponse
from ._base import NamespacedClient
from .utils import SKIP_IN_PATH, _quote, _rewrite_parameters
class ClusterClient(NamespacedClient):
@_rewrite_parameters(
body_fields=("current_node", "index", "primary", "shard"),
)
def allocation_explain(
self,
*,
current_node: 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,
include_disk_info: t.Optional[bool] = None,
include_yes_decisions: t.Optional[bool] = None,
index: t.Optional[str] = None,
master_timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
pretty: t.Optional[bool] = None,
primary: t.Optional[bool] = None,
shard: t.Optional[int] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Explain the shard allocations.
Get explanations for shard allocations in the cluster.
For unassigned shards, it provides an explanation for why the shard is unassigned.
For assigned shards, it provides an explanation for why the shard is remaining on its current node and has not moved or rebalanced to another node.
This API can be very useful when attempting to diagnose why a shard is unassigned or why a shard continues to remain on its current node when you might expect otherwise.
Refer to the linked documentation for examples of how to troubleshoot allocation issues using this API.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-allocation-explain>`_
:param current_node: Specifies the node ID or the name of the node to only explain
a shard that is currently located on the specified node.
:param include_disk_info: If true, returns information about disk usage and shard
sizes.
:param include_yes_decisions: If true, returns YES decisions in explanation.
:param index: Specifies the name of the index that you would like an explanation
for.
:param master_timeout: Period to wait for a connection to the master node.
:param primary: If true, returns explanation for the primary shard for the given
shard ID.
:param shard: Specifies the ID of the shard that you would like an explanation
for.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_cluster/allocation/explain"
__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 include_disk_info is not None:
__query["include_disk_info"] = include_disk_info
if include_yes_decisions is not None:
__query["include_yes_decisions"] = include_yes_decisions
if master_timeout is not None:
__query["master_timeout"] = master_timeout
if pretty is not None:
__query["pretty"] = pretty
if not __body:
if current_node is not None:
__body["current_node"] = current_node
if index is not None:
__body["index"] = index
if primary is not None:
__body["primary"] = primary
if shard is not None:
__body["shard"] = shard
if not __body:
__body = None # type: ignore[assignment]
__headers = {"accept": "application/json"}
if __body is not None:
__headers["content-type"] = "application/json"
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="cluster.allocation_explain",
path_parts=__path_parts,
)
@_rewrite_parameters()
def delete_component_template(
self,
*,
name: t.Union[str, t.Sequence[str]],
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,
timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Delete component templates.
Component templates are building blocks for constructing index templates that specify index mappings, settings, and aliases.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-put-component-template>`_
:param name: Comma-separated list or wildcard expression of component template
names used to limit the request.
:param master_timeout: Period to wait for a connection to the master node. If
no response is received before the timeout expires, the request fails and
returns an error.
:param timeout: Period to wait for a response. If no response is received before
the timeout expires, the request fails and returns an error.
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
__path = f'/_component_template/{__path_parts["name"]}'
__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
if timeout is not None:
__query["timeout"] = timeout
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"DELETE",
__path,
params=__query,
headers=__headers,
endpoint_id="cluster.delete_component_template",
path_parts=__path_parts,
)
@_rewrite_parameters()
def delete_voting_config_exclusions(
self,
*,
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,
wait_for_removal: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Clear cluster voting config exclusions.
Remove master-eligible nodes from the voting configuration exclusion list.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-post-voting-config-exclusions>`_
:param master_timeout: Period to wait for a connection to the master node.
:param wait_for_removal: Specifies whether to wait for all excluded nodes to
be removed from the cluster before clearing the voting configuration exclusions
list. Defaults to true, meaning that all excluded nodes must be removed from
the cluster before this API takes any action. If set to false then the voting
configuration exclusions list is cleared even if some excluded nodes are
still in the cluster.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_cluster/voting_config_exclusions"
__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
if wait_for_removal is not None:
__query["wait_for_removal"] = wait_for_removal
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"DELETE",
__path,
params=__query,
headers=__headers,
endpoint_id="cluster.delete_voting_config_exclusions",
path_parts=__path_parts,
)
@_rewrite_parameters()
def exists_component_template(
self,
*,
name: t.Union[str, t.Sequence[str]],
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
local: t.Optional[bool] = None,
master_timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
pretty: t.Optional[bool] = None,
) -> HeadApiResponse:
"""
.. raw:: html
<p>Check component templates.
Returns information about whether a particular component template exists.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-put-component-template>`_
:param name: Comma-separated list of component template names used to limit the
request. Wildcard (*) expressions are supported.
:param local: If true, the request retrieves information from the local node
only. Defaults to false, which means information is retrieved from the master
node.
:param master_timeout: Period to wait for a connection to the master node. If
no response is received before the timeout expires, the request fails and
returns an error.
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
__path = f'/_component_template/{__path_parts["name"]}'
__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 local is not None:
__query["local"] = local
if master_timeout is not None:
__query["master_timeout"] = master_timeout
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"HEAD",
__path,
params=__query,
headers=__headers,
endpoint_id="cluster.exists_component_template",
path_parts=__path_parts,
)
@_rewrite_parameters()
def get_component_template(
self,
*,
name: t.Optional[str] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
flat_settings: t.Optional[bool] = None,
human: t.Optional[bool] = None,
include_defaults: t.Optional[bool] = None,
local: t.Optional[bool] = None,
master_timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
pretty: t.Optional[bool] = None,
settings_filter: t.Optional[t.Union[str, t.Sequence[str]]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get component templates.
Get information about component templates.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-put-component-template>`_
:param name: Comma-separated list of component template names used to limit the
request. Wildcard (`*`) expressions are supported.
:param flat_settings: If `true`, returns settings in flat format.
:param include_defaults: Return all default configurations for the component
template (default: false)
:param local: If `true`, the request retrieves information from the local node
only. If `false`, information is retrieved from the master node.
:param master_timeout: Period to wait for a connection to the master node. If
no response is received before the timeout expires, the request fails and
returns an error.
:param settings_filter: Filter out results, for example to filter out sensitive
information. Supports wildcards or full settings keys
"""
__path_parts: t.Dict[str, str]
if name not in SKIP_IN_PATH:
__path_parts = {"name": _quote(name)}
__path = f'/_component_template/{__path_parts["name"]}'
else:
__path_parts = {}
__path = "/_component_template"
__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 flat_settings is not None:
__query["flat_settings"] = flat_settings
if human is not None:
__query["human"] = human
if include_defaults is not None:
__query["include_defaults"] = include_defaults
if local is not None:
__query["local"] = local
if master_timeout is not None:
__query["master_timeout"] = master_timeout
if pretty is not None:
__query["pretty"] = pretty
if settings_filter is not None:
__query["settings_filter"] = settings_filter
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="cluster.get_component_template",
path_parts=__path_parts,
)
@_rewrite_parameters()
def get_settings(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
flat_settings: t.Optional[bool] = None,
human: t.Optional[bool] = None,
include_defaults: t.Optional[bool] = None,
master_timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
pretty: t.Optional[bool] = None,
timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get cluster-wide settings.</p>
<p>By default, it returns only settings that have been explicitly defined.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-get-settings>`_
:param flat_settings: If `true`, returns settings in flat format.
:param include_defaults: If `true`, returns default cluster settings from the
local node.
:param master_timeout: Period to wait for a connection to the master node. If
no response is received before the timeout expires, the request fails and
returns an error.
:param timeout: Period to wait for a response. If no response is received before
the timeout expires, the request fails and returns an error.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_cluster/settings"
__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 flat_settings is not None:
__query["flat_settings"] = flat_settings
if human is not None:
__query["human"] = human
if include_defaults is not None:
__query["include_defaults"] = include_defaults
if master_timeout is not None:
__query["master_timeout"] = master_timeout
if pretty is not None:
__query["pretty"] = pretty
if timeout is not None:
__query["timeout"] = timeout
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="cluster.get_settings",
path_parts=__path_parts,
)
@_rewrite_parameters()
def health(
self,
*,
index: t.Optional[t.Union[str, t.Sequence[str]]] = 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,
level: t.Optional[
t.Union[str, t.Literal["cluster", "indices", "shards"]]
] = None,
local: t.Optional[bool] = None,
master_timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
pretty: t.Optional[bool] = None,
timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union[str, t.Literal["all", "index-setting"]]]
] = None,
wait_for_events: t.Optional[
t.Union[
str,
t.Literal["high", "immediate", "languid", "low", "normal", "urgent"],
]
] = None,
wait_for_no_initializing_shards: t.Optional[bool] = None,
wait_for_no_relocating_shards: t.Optional[bool] = None,
wait_for_nodes: t.Optional[t.Union[int, str]] = None,
wait_for_status: t.Optional[
t.Union[str, t.Literal["green", "red", "unavailable", "unknown", "yellow"]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get the cluster health status.</p>
<p>You can also use the API to get the health status of only specified data streams and indices.
For data streams, the API retrieves the health status of the stream’s backing indices.</p>
<p>The cluster health status is: green, yellow or red.
On the shard level, a red status indicates that the specific shard is not allocated in the cluster. Yellow means that the primary shard is allocated but replicas are not. Green means that all shards are allocated.
The index level status is controlled by the worst shard status.</p>
<p>One of the main benefits of the API is the ability to wait until the cluster reaches a certain high watermark health level.
The cluster status is controlled by the worst index status.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-health>`_
:param index: Comma-separated list of data streams, indices, and index aliases
used to limit the request. Wildcard expressions (`*`) are supported. To target
all data streams and indices in a cluster, omit this parameter or use _all
or `*`.
:param expand_wildcards: Whether to expand wildcard expression to concrete indices
that are open, closed or both.
:param level: Can be one of cluster, indices or shards. Controls the details
level of the health information returned.
:param local: If true, the request retrieves information from the local node
only. Defaults to false, which means information is retrieved from the master
node.
:param master_timeout: Period to wait for a connection to the master node. If
no response is received before the timeout expires, the request fails and
returns an error.
:param timeout: Period to wait for a response. If no response is received before
the timeout expires, the request fails and returns an error.
:param wait_for_active_shards: A number controlling to how many active shards
to wait for, all to wait for all shards in the cluster to be active, or 0
to not wait.
:param wait_for_events: Can be one of immediate, urgent, high, normal, low, languid.
Wait until all currently queued events with the given priority are processed.
:param wait_for_no_initializing_shards: A boolean value which controls whether
to wait (until the timeout provided) for the cluster to have no shard initializations.
Defaults to false, which means it will not wait for initializing shards.
:param wait_for_no_relocating_shards: A boolean value which controls whether
to wait (until the timeout provided) for the cluster to have no shard relocations.
Defaults to false, which means it will not wait for relocating shards.
:param wait_for_nodes: The request waits until the specified number N of nodes
is available. It also accepts >=N, <=N, >N and <N. Alternatively, it is possible
to use ge(N), le(N), gt(N) and lt(N) notation.
:param wait_for_status: One of green, yellow or red. Will wait (until the timeout
provided) until the status of the cluster changes to the one provided or
better, i.e. green > yellow > red. By default, will not wait for any status.
"""
__path_parts: t.Dict[str, str]
if index not in SKIP_IN_PATH:
__path_parts = {"index": _quote(index)}
__path = f'/_cluster/health/{__path_parts["index"]}'
else:
__path_parts = {}
__path = "/_cluster/health"
__query: t.Dict[str, t.Any] = {}
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 level is not None:
__query["level"] = level
if local is not None:
__query["local"] = local
if master_timeout is not None:
__query["master_timeout"] = master_timeout
if pretty is not None:
__query["pretty"] = pretty
if timeout is not None:
__query["timeout"] = timeout
if wait_for_active_shards is not None:
__query["wait_for_active_shards"] = wait_for_active_shards
if wait_for_events is not None:
__query["wait_for_events"] = wait_for_events
if wait_for_no_initializing_shards is not None:
__query["wait_for_no_initializing_shards"] = wait_for_no_initializing_shards
if wait_for_no_relocating_shards is not None:
__query["wait_for_no_relocating_shards"] = wait_for_no_relocating_shards
if wait_for_nodes is not None:
__query["wait_for_nodes"] = wait_for_nodes
if wait_for_status is not None:
__query["wait_for_status"] = wait_for_status
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="cluster.health",
path_parts=__path_parts,
)
@_rewrite_parameters()
def info(
self,
*,
target: t.Union[
t.Sequence[
t.Union[
str, t.Literal["_all", "http", "ingest", "script", "thread_pool"]
]
],
t.Union[str, t.Literal["_all", "http", "ingest", "script", "thread_pool"]],
],
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get cluster info.
Returns basic information about the cluster.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-info>`_
:param target: Limits the information returned to the specific target. Supports
a comma-separated list, such as http,ingest.
"""
if target in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'target'")
__path_parts: t.Dict[str, str] = {"target": _quote(target)}
__path = f'/_info/{__path_parts["target"]}'
__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 pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="cluster.info",
path_parts=__path_parts,
)
@_rewrite_parameters()
def pending_tasks(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
local: 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 the pending cluster tasks.
Get information about cluster-level changes (such as create index, update mapping, allocate or fail shard) that have not yet taken effect.</p>
<p>NOTE: This API returns a list of any pending updates to the cluster state.
These are distinct from the tasks reported by the task management API which include periodic tasks and tasks initiated by the user, such as node stats, search queries, or create index requests.
However, if a user-initiated task such as a create index command causes a cluster state update, the activity of this task might be reported by both task api and pending cluster tasks API.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-pending-tasks>`_
:param local: If `true`, the request retrieves information from the local node
only. If `false`, information is retrieved from the master node.
:param master_timeout: Period to wait for a connection to the master node. If
no response is received before the timeout expires, the request fails and
returns an error.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_cluster/pending_tasks"
__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 local is not None:
__query["local"] = local
if master_timeout is not None:
__query["master_timeout"] = master_timeout
if pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="cluster.pending_tasks",
path_parts=__path_parts,
)
@_rewrite_parameters()
def post_voting_config_exclusions(
self,
*,
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,
node_ids: t.Optional[t.Union[str, t.Sequence[str]]] = None,
node_names: t.Optional[t.Union[str, t.Sequence[str]]] = None,
pretty: t.Optional[bool] = None,
timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Update voting configuration exclusions.
Update the cluster voting config exclusions by node IDs or node names.
By default, if there are more than three master-eligible nodes in the cluster and you remove fewer than half of the master-eligible nodes in the cluster at once, the voting configuration automatically shrinks.
If you want to shrink the voting configuration to contain fewer than three nodes or to remove half or more of the master-eligible nodes in the cluster at once, use this API to remove departing nodes from the voting configuration manually.
The API adds an entry for each specified node to the cluster’s voting configuration exclusions list.
It then waits until the cluster has reconfigured its voting configuration to exclude the specified nodes.</p>
<p>Clusters should have no voting configuration exclusions in normal operation.
Once the excluded nodes have stopped, clear the voting configuration exclusions with <code>DELETE /_cluster/voting_config_exclusions</code>.
This API waits for the nodes to be fully removed from the cluster before it returns.
If your cluster has voting configuration exclusions for nodes that you no longer intend to remove, use <code>DELETE /_cluster/voting_config_exclusions?wait_for_removal=false</code> to clear the voting configuration exclusions without waiting for the nodes to leave the cluster.</p>
<p>A response to <code>POST /_cluster/voting_config_exclusions</code> with an HTTP status code of 200 OK guarantees that the node has been removed from the voting configuration and will not be reinstated until the voting configuration exclusions are cleared by calling <code>DELETE /_cluster/voting_config_exclusions</code>.
If the call to <code>POST /_cluster/voting_config_exclusions</code> fails or returns a response with an HTTP status code other than 200 OK then the node may not have been removed from the voting configuration.
In that case, you may safely retry the call.</p>
<p>NOTE: Voting exclusions are required only when you remove at least half of the master-eligible nodes from a cluster in a short time period.
They are not required when removing master-ineligible nodes or when removing fewer than half of the master-eligible nodes.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-post-voting-config-exclusions>`_
:param master_timeout: Period to wait for a connection to the master node.
:param node_ids: A comma-separated list of the persistent ids of the nodes to
exclude from the voting configuration. If specified, you may not also specify
node_names.
:param node_names: A comma-separated list of the names of the nodes to exclude
from the voting configuration. If specified, you may not also specify node_ids.
:param timeout: When adding a voting configuration exclusion, the API waits for
the specified nodes to be excluded from the voting configuration before returning.
If the timeout expires before the appropriate condition is satisfied, the
request fails and returns an error.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_cluster/voting_config_exclusions"
__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 node_ids is not None:
__query["node_ids"] = node_ids
if node_names is not None:
__query["node_names"] = node_names
if pretty is not None:
__query["pretty"] = pretty
if timeout is not None:
__query["timeout"] = timeout
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
endpoint_id="cluster.post_voting_config_exclusions",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("template", "deprecated", "meta", "version"),
parameter_aliases={"_meta": "meta"},
)
def put_component_template(
self,
*,
name: str,
template: t.Optional[t.Mapping[str, t.Any]] = None,
cause: t.Optional[str] = None,
create: t.Optional[bool] = None,
deprecated: t.Optional[bool] = 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,
meta: t.Optional[t.Mapping[str, t.Any]] = None,
pretty: t.Optional[bool] = None,
version: t.Optional[int] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create or update a component template.
Component templates are building blocks for constructing index templates that specify index mappings, settings, and aliases.</p>
<p>An index template can be composed of multiple component templates.
To use a component template, specify it in an index template’s <code>composed_of</code> list.
Component templates are only applied to new data streams and indices as part of a matching index template.</p>
<p>Settings and mappings specified directly in the index template or the create index request override any settings or mappings specified in a component template.</p>
<p>Component templates are only used during index creation.
For data streams, this includes data stream creation and the creation of a stream’s backing indices.
Changes to component templates do not affect existing indices, including a stream’s backing indices.</p>
<p>You can use C-style <code>/* *\\/</code> block comments in component templates.
You can include comments anywhere in the request body except before the opening curly bracket.</p>
<p><strong>Applying component templates</strong></p>
<p>You cannot directly apply a component template to a data stream or index.
To be applied, a component template must be included in an index template's <code>composed_of</code> list.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-put-component-template>`_
:param name: Name of the component template to create. Elasticsearch includes
the following built-in component templates: `logs-mappings`; `logs-settings`;
`metrics-mappings`; `metrics-settings`;`synthetics-mapping`; `synthetics-settings`.
Elastic Agent uses these templates to configure backing indices for its data
streams. If you use Elastic Agent and want to overwrite one of these templates,
set the `version` for your replacement template higher than the current version.
If you don’t use Elastic Agent and want to disable all built-in component
and index templates, set `stack.templates.enabled` to `false` using the cluster
update settings API.
:param template: The template to be applied which includes mappings, settings,
or aliases configuration.
:param cause: User defined reason for create the component template.
:param create: If `true`, this request cannot replace or update existing component
templates.
:param deprecated: Marks this index template as deprecated. When creating or
updating a non-deprecated index template that uses deprecated components,
Elasticsearch will emit a deprecation warning.
:param master_timeout: Period to wait for a connection to the master node. If
no response is received before the timeout expires, the request fails and
returns an error.
:param meta: Optional user metadata about the component template. It may have
any contents. This map is not automatically generated by Elasticsearch. This
information is stored in the cluster state, so keeping it short is preferable.
To unset `_meta`, replace the template without specifying this information.
:param version: Version number used to manage component templates externally.
This number isn't automatically generated or incremented by Elasticsearch.
To unset a version, replace the template without specifying a version.
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
if template is None and body is None:
raise ValueError("Empty value passed for parameter 'template'")
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
__path = f'/_component_template/{__path_parts["name"]}'
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if cause is not None:
__query["cause"] = cause
if create is not None:
__query["create"] = create
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 not __body:
if template is not None:
__body["template"] = template
if deprecated is not None:
__body["deprecated"] = deprecated
if meta is not None:
__body["_meta"] = meta
if version is not None:
__body["version"] = version
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="cluster.put_component_template",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("persistent", "transient"),
)
def put_settings(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
flat_settings: t.Optional[bool] = None,
human: t.Optional[bool] = None,
master_timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
persistent: t.Optional[t.Mapping[str, t.Any]] = None,
pretty: t.Optional[bool] = None,
timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
transient: t.Optional[t.Mapping[str, t.Any]] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Update the cluster settings.</p>
<p>Configure and update dynamic settings on a running cluster.
You can also configure dynamic settings locally on an unstarted or shut down node in <code>elasticsearch.yml</code>.</p>
<p>Updates made with this API can be persistent, which apply across cluster restarts, or transient, which reset after a cluster restart.
You can also reset transient or persistent settings by assigning them a null value.</p>
<p>If you configure the same setting using multiple methods, Elasticsearch applies the settings in following order of precedence: 1) Transient setting; 2) Persistent setting; 3) <code>elasticsearch.yml</code> setting; 4) Default setting value.
For example, you can apply a transient setting to override a persistent setting or <code>elasticsearch.yml</code> setting.
However, a change to an <code>elasticsearch.yml</code> setting will not override a defined transient or persistent setting.</p>
<p>TIP: In Elastic Cloud, use the user settings feature to configure all cluster settings. This method automatically rejects unsafe settings that could break your cluster.
If you run Elasticsearch on your own hardware, use this API to configure dynamic cluster settings.
Only use <code>elasticsearch.yml</code> for static cluster settings and node settings.
The API doesn’t require a restart and ensures a setting’s value is the same on all nodes.</p>
<p>WARNING: Transient cluster settings are no longer recommended. Use persistent cluster settings instead.
If a cluster becomes unstable, transient settings can clear unexpectedly, resulting in a potentially undesired cluster configuration.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-put-settings>`_
:param flat_settings: Return settings in flat format (default: false)
:param master_timeout: Explicit operation timeout for connection to master node
:param persistent: The settings that persist after the cluster restarts.
:param timeout: Explicit operation timeout
:param transient: The settings that do not persist after the cluster restarts.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_cluster/settings"
__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 flat_settings is not None:
__query["flat_settings"] = flat_settings
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 timeout is not None:
__query["timeout"] = timeout
if not __body:
if persistent is not None:
__body["persistent"] = persistent
if transient is not None:
__body["transient"] = transient
__headers = {"accept": "application/json", "content-type": "application/json"}
return self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="cluster.put_settings",
path_parts=__path_parts,
)
@_rewrite_parameters()
def remote_info(
self,
*,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get remote cluster information.</p>
<p>Get information about configured remote clusters.
The API returns connection and endpoint information keyed by the configured remote cluster alias.</p>
<blockquote>
<p>info
This API returns information that reflects current state on the local cluster.
The <code>connected</code> field does not necessarily reflect whether a remote cluster is down or unavailable, only whether there is currently an open connection to it.
Elasticsearch does not spontaneously try to reconnect to a disconnected remote cluster.
To trigger a reconnection, attempt a cross-cluster search, ES|QL cross-cluster search, or try the <a href="https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-resolve-cluster">resolve cluster endpoint</a>.</p>
</blockquote>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-remote-info>`_
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_remote/info"
__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 pretty is not None:
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="cluster.remote_info",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("commands",),
)
def reroute(
self,
*,
commands: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None,
dry_run: t.Optional[bool] = None,
error_trace: t.Optional[bool] = None,
explain: 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,
metric: t.Optional[t.Union[str, t.Sequence[str]]] = None,
pretty: t.Optional[bool] = None,
retry_failed: t.Optional[bool] = None,
timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Reroute the cluster.
Manually change the allocation of individual shards in the cluster.
For example, a shard can be moved from one node to another explicitly, an allocation can be canceled, and an unassigned shard can be explicitly allocated to a specific node.</p>
<p>It is important to note that after processing any reroute commands Elasticsearch will perform rebalancing as normal (respecting the values of settings such as <code>cluster.routing.rebalance.enable</code>) in order to remain in a balanced state.
For example, if the requested allocation includes moving a shard from node1 to node2 then this may cause a shard to be moved from node2 back to node1 to even things out.</p>
<p>The cluster can be set to disable allocations using the <code>cluster.routing.allocation.enable</code> setting.
If allocations are disabled then the only allocations that will be performed are explicit ones given using the reroute command, and consequent allocations due to rebalancing.</p>
<p>The cluster will attempt to allocate a shard a maximum of <code>index.allocation.max_retries</code> times in a row (defaults to <code>5</code>), before giving up and leaving the shard unallocated.
This scenario can be caused by structural problems such as having an analyzer which refers to a stopwords file which doesn’t exist on all nodes.</p>
<p>Once the problem has been corrected, allocation can be manually retried by calling the reroute API with the <code>?retry_failed</code> URI query parameter, which will attempt a single retry round for these shards.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-reroute>`_
:param commands: Defines the commands to perform.
:param dry_run: If true, then the request simulates the operation. It will calculate
the result of applying the commands to the current cluster state and return
the resulting cluster state after the commands (and rebalancing) have been
applied; it will not actually perform the requested changes.
:param explain: If true, then the response contains an explanation of why the
commands can or cannot run.
:param master_timeout: Period to wait for a connection to the master node. If
no response is received before the timeout expires, the request fails and
returns an error.
:param metric: Limits the information returned to the specified metrics.
:param retry_failed: If true, then retries allocation of shards that are blocked
due to too many subsequent allocation failures.
:param timeout: Period to wait for a response. If no response is received before
the timeout expires, the request fails and returns an error.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_cluster/reroute"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
if dry_run is not None:
__query["dry_run"] = dry_run
if error_trace is not None:
__query["error_trace"] = error_trace
if explain is not None:
__query["explain"] = explain
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 metric is not None:
__query["metric"] = metric
if pretty is not None:
__query["pretty"] = pretty
if retry_failed is not None:
__query["retry_failed"] = retry_failed
if timeout is not None:
__query["timeout"] = timeout
if not __body:
if commands is not None:
__body["commands"] = commands
if not __body:
__body = None # type: ignore[assignment]
__headers = {"accept": "application/json"}
if __body is not None:
__headers["content-type"] = "application/json"
return self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="cluster.reroute",
path_parts=__path_parts,
)
@_rewrite_parameters()
def state(
self,
*,
metric: t.Optional[t.Union[str, t.Sequence[str]]] = None,
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,
flat_settings: t.Optional[bool] = None,
human: t.Optional[bool] = None,
ignore_unavailable: t.Optional[bool] = None,
local: t.Optional[bool] = None,
master_timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
pretty: t.Optional[bool] = None,
wait_for_metadata_version: t.Optional[int] = None,
wait_for_timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get the cluster state.
Get comprehensive information about the state of the cluster.</p>
<p>The cluster state is an internal data structure which keeps track of a variety of information needed by every node, including the identity and attributes of the other nodes in the cluster; cluster-wide settings; index metadata, including the mapping and settings for each index; the location and status of every shard copy in the cluster.</p>
<p>The elected master node ensures that every node in the cluster has a copy of the same cluster state.
This API lets you retrieve a representation of this internal state for debugging or diagnostic purposes.
You may need to consult the Elasticsearch source code to determine the precise meaning of the response.</p>
<p>By default the API will route requests to the elected master node since this node is the authoritative source of cluster states.
You can also retrieve the cluster state held on the node handling the API request by adding the <code>?local=true</code> query parameter.</p>
<p>Elasticsearch may need to expend significant effort to compute a response to this API in larger clusters, and the response may comprise a very large quantity of data.
If you use this API repeatedly, your cluster may become unstable.</p>
<p>WARNING: The response is a representation of an internal data structure.
Its format is not subject to the same compatibility guarantees as other more stable APIs and may change from version to version.
Do not query this API using external monitoring tools.
Instead, obtain the information you require using other more stable cluster APIs.</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-state>`_
:param metric: Limit the information returned to the specified metrics
:param index: A comma-separated list of index names; use `_all` or empty string
to perform the operation on all indices
: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 flat_settings: Return settings in flat format (default: false)
:param ignore_unavailable: Whether specified concrete indices should be ignored
when unavailable (missing or closed)
:param local: Return local information, do not retrieve the state from master
node (default: false)
:param master_timeout: Specify timeout for connection to master
:param wait_for_metadata_version: Wait for the metadata version to be equal or
greater than the specified metadata version
:param wait_for_timeout: The maximum time to wait for wait_for_metadata_version
before timing out
"""
__path_parts: t.Dict[str, str]
if metric not in SKIP_IN_PATH and index not in SKIP_IN_PATH:
__path_parts = {"metric": _quote(metric), "index": _quote(index)}
__path = f'/_cluster/state/{__path_parts["metric"]}/{__path_parts["index"]}'
elif metric not in SKIP_IN_PATH:
__path_parts = {"metric": _quote(metric)}
__path = f'/_cluster/state/{__path_parts["metric"]}'
elif index not in SKIP_IN_PATH:
__path_parts = {"index": _quote(index)}
__path = f'/_cluster/state/_all/{__path_parts["index"]}'
else:
__path_parts = {}
__path = "/_cluster/state"
__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 flat_settings is not None:
__query["flat_settings"] = flat_settings
if human is not None:
__query["human"] = human
if ignore_unavailable is not None:
__query["ignore_unavailable"] = ignore_unavailable
if local is not None:
__query["local"] = local
if master_timeout is not None:
__query["master_timeout"] = master_timeout
if pretty is not None:
__query["pretty"] = pretty
if wait_for_metadata_version is not None:
__query["wait_for_metadata_version"] = wait_for_metadata_version
if wait_for_timeout is not None:
__query["wait_for_timeout"] = wait_for_timeout
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="cluster.state",
path_parts=__path_parts,
)
@_rewrite_parameters()
def 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,
include_remotes: t.Optional[bool] = None,
pretty: t.Optional[bool] = None,
timeout: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get cluster statistics.
Get basic index metrics (shard numbers, store size, memory usage) and information about the current nodes that form the cluster (number, roles, os, jvm versions, memory usage, cpu and installed plugins).</p>
`<https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-cluster-stats>`_
:param node_id: Comma-separated list of node filters used to limit returned information.
Defaults to all nodes in the cluster.
:param include_remotes: Include remote cluster data into the response
:param timeout: Period to wait for each node to respond. If a node does not respond
before its timeout expires, the response does not include its stats. However,
timed out nodes are included in the response’s `_nodes.failed` property.
Defaults to no timeout.
"""
__path_parts: t.Dict[str, str]
if node_id not in SKIP_IN_PATH:
__path_parts = {"node_id": _quote(node_id)}
__path = f'/_cluster/stats/nodes/{__path_parts["node_id"]}'
else:
__path_parts = {}
__path = "/_cluster/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 include_remotes is not None:
__query["include_remotes"] = include_remotes
if pretty is not None:
__query["pretty"] = pretty
if timeout is not None:
__query["timeout"] = timeout
__headers = {"accept": "application/json"}
return self.perform_request( # type: ignore[return-value]
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="cluster.stats",
path_parts=__path_parts,
)
|