-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathindices.py
5378 lines (5074 loc) · 261 KB
/
indices.py
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
# 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,
Stability,
_quote,
_rewrite_parameters,
_stability_warning,
)
class IndicesClient(NamespacedClient):
@_rewrite_parameters()
async def add_block(
self,
*,
index: str,
block: t.Union[str, t.Literal["metadata", "read", "read_only", "write"]],
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,
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>Add an index block.
Limits the operations allowed on an index by blocking specific operation types.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/index-modules-blocks.html>`_
:param index: A comma separated list of indices to add a block to
:param block: The block to add (one of read, write, read_only or metadata)
: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)
:param master_timeout: Specify timeout for connection to master
:param timeout: Explicit operation timeout
"""
if index in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'index'")
if block in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'block'")
__path_parts: t.Dict[str, str] = {
"index": _quote(index),
"block": _quote(block),
}
__path = f'/{__path_parts["index"]}/_block/{__path_parts["block"]}'
__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 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 await self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
endpoint_id="indices.add_block",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=(
"analyzer",
"attributes",
"char_filter",
"explain",
"field",
"filter",
"normalizer",
"text",
"tokenizer",
),
)
async def analyze(
self,
*,
index: t.Optional[str] = None,
analyzer: t.Optional[str] = None,
attributes: t.Optional[t.Sequence[str]] = None,
char_filter: t.Optional[t.Sequence[t.Union[str, t.Mapping[str, t.Any]]]] = None,
error_trace: t.Optional[bool] = None,
explain: t.Optional[bool] = None,
field: t.Optional[str] = None,
filter: t.Optional[t.Sequence[t.Union[str, t.Mapping[str, t.Any]]]] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
normalizer: t.Optional[str] = None,
pretty: t.Optional[bool] = None,
text: t.Optional[t.Union[str, t.Sequence[str]]] = None,
tokenizer: t.Optional[t.Union[str, t.Mapping[str, t.Any]]] = None,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get tokens from text analysis.
The analyze API performs analysis on a text string and returns the resulting tokens.</p>
<p>Generating excessive amount of tokens may cause a node to run out of memory.
The <code>index.analyze.max_token_count</code> setting enables you to limit the number of tokens that can be produced.
If more than this limit of tokens gets generated, an error occurs.
The <code>_analyze</code> endpoint without a specified index will always use <code>10000</code> as its limit.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/indices-analyze.html>`_
:param index: Index used to derive the analyzer. If specified, the `analyzer`
or field parameter overrides this value. If no index is specified or the
index does not have a default analyzer, the analyze API uses the standard
analyzer.
:param analyzer: The name of the analyzer that should be applied to the provided
`text`. This could be a built-in analyzer, or an analyzer that’s been configured
in the index.
:param attributes: Array of token attributes used to filter the output of the
`explain` parameter.
:param char_filter: Array of character filters used to preprocess characters
before the tokenizer.
:param explain: If `true`, the response includes token attributes and additional
details.
:param field: Field used to derive the analyzer. To use this parameter, you must
specify an index. If specified, the `analyzer` parameter overrides this value.
:param filter: Array of token filters used to apply after the tokenizer.
:param normalizer: Normalizer to use to convert text into a single token.
:param text: Text to analyze. If an array of strings is provided, it is analyzed
as a multi-value field.
:param tokenizer: Tokenizer to use to convert text into tokens.
"""
__path_parts: t.Dict[str, str]
if index not in SKIP_IN_PATH:
__path_parts = {"index": _quote(index)}
__path = f'/{__path_parts["index"]}/_analyze'
else:
__path_parts = {}
__path = "/_analyze"
__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 pretty is not None:
__query["pretty"] = pretty
if not __body:
if analyzer is not None:
__body["analyzer"] = analyzer
if attributes is not None:
__body["attributes"] = attributes
if char_filter is not None:
__body["char_filter"] = char_filter
if explain is not None:
__body["explain"] = explain
if field is not None:
__body["field"] = field
if filter is not None:
__body["filter"] = filter
if normalizer is not None:
__body["normalizer"] = normalizer
if text is not None:
__body["text"] = text
if tokenizer is not None:
__body["tokenizer"] = tokenizer
if not __body:
__body = None # type: ignore[assignment]
__headers = {"accept": "application/json"}
if __body is not None:
__headers["content-type"] = "application/json"
return await self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="indices.analyze",
path_parts=__path_parts,
)
@_rewrite_parameters()
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,
fielddata: t.Optional[bool] = None,
fields: t.Optional[t.Union[str, t.Sequence[str]]] = 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,
query: t.Optional[bool] = None,
request: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Clear the cache.
Clear the cache of one or more indices.
For data streams, the API clears the caches of the stream's backing indices.</p>
<p>By default, the clear cache API clears all caches.
To clear only specific caches, use the <code>fielddata</code>, <code>query</code>, or <code>request</code> parameters.
To clear the cache only of specific fields, use the <code>fields</code> parameter.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/indices-clearcache.html>`_
:param index: Comma-separated list of data streams, indices, and aliases used
to limit the request. Supports wildcards (`*`). To target all data streams
and indices, omit this parameter or use `*` or `_all`.
:param allow_no_indices: If `false`, the request returns an error if any wildcard
expression, index alias, or `_all` value targets only missing or closed indices.
This behavior applies even if the request targets other open indices.
:param expand_wildcards: Type of index that wildcard patterns can match. If the
request can target data streams, this argument determines whether wildcard
expressions match hidden data streams. Supports comma-separated values, such
as `open,hidden`. Valid values are: `all`, `open`, `closed`, `hidden`, `none`.
:param fielddata: If `true`, clears the fields cache. Use the `fields` parameter
to clear the cache of specific fields only.
:param fields: Comma-separated list of field names used to limit the `fielddata`
parameter.
:param ignore_unavailable: If `false`, the request returns an error if it targets
a missing or closed index.
:param query: If `true`, clears the query cache.
:param request: If `true`, clears the request cache.
"""
__path_parts: t.Dict[str, str]
if index not in SKIP_IN_PATH:
__path_parts = {"index": _quote(index)}
__path = f'/{__path_parts["index"]}/_cache/clear'
else:
__path_parts = {}
__path = "/_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 fielddata is not None:
__query["fielddata"] = fielddata
if fields is not None:
__query["fields"] = fields
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
if query is not None:
__query["query"] = query
if request is not None:
__query["request"] = request
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
endpoint_id="indices.clear_cache",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("aliases", "settings"),
)
async def clone(
self,
*,
index: str,
target: str,
aliases: t.Optional[t.Mapping[str, t.Mapping[str, t.Any]]] = 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,
settings: t.Optional[t.Mapping[str, t.Any]] = 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,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Clone an index.
Clone an existing index into a new index.
Each original primary shard is cloned into a new primary shard in the new index.</p>
<p>IMPORTANT: Elasticsearch does not apply index templates to the resulting index.
The API also does not copy index metadata from the original index.
Index metadata includes aliases, index lifecycle management phase definitions, and cross-cluster replication (CCR) follower information.
For example, if you clone a CCR follower index, the resulting clone will not be a follower index.</p>
<p>The clone API copies most index settings from the source index to the resulting index, with the exception of <code>index.number_of_replicas</code> and <code>index.auto_expand_replicas</code>.
To set the number of replicas in the resulting index, configure these settings in the clone request.</p>
<p>Cloning works as follows:</p>
<ul>
<li>First, it creates a new target index with the same definition as the source index.</li>
<li>Then it hard-links segments from the source index into the target index. If the file system does not support hard-linking, all segments are copied into the new index, which is a much more time consuming process.</li>
<li>Finally, it recovers the target index as though it were a closed index which had just been re-opened.</li>
</ul>
<p>IMPORTANT: Indices can only be cloned if they meet the following requirements:</p>
<ul>
<li>The index must be marked as read-only and have a cluster health status of green.</li>
<li>The target index must not exist.</li>
<li>The source index must have the same number of primary shards as the target index.</li>
<li>The node handling the clone process must have sufficient free disk space to accommodate a second copy of the existing index.</li>
</ul>
<p>The current write index on a data stream cannot be cloned.
In order to clone the current write index, the data stream must first be rolled over so that a new write index is created and then the previous write index can be cloned.</p>
<p>NOTE: Mappings cannot be specified in the <code>_clone</code> request. The mappings of the source index will be used for the target index.</p>
<p><strong>Monitor the cloning process</strong></p>
<p>The cloning process can be monitored with the cat recovery API or the cluster health API can be used to wait until all primary shards have been allocated by setting the <code>wait_for_status</code> parameter to <code>yellow</code>.</p>
<p>The <code>_clone</code> API returns as soon as the target index has been added to the cluster state, before any shards have been allocated.
At this point, all shards are in the state unassigned.
If, for any reason, the target index can't be allocated, its primary shard will remain unassigned until it can be allocated on that node.</p>
<p>Once the primary shard is allocated, it moves to state initializing, and the clone process begins.
When the clone operation completes, the shard will become active.
At that point, Elasticsearch will try to allocate any replicas and may decide to relocate the primary shard to another node.</p>
<p><strong>Wait for active shards</strong></p>
<p>Because the clone operation creates a new index to clone the shards to, the wait for active shards setting on index creation applies to the clone index action as well.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/indices-clone-index.html>`_
:param index: Name of the source index to clone.
:param target: Name of the target index to create.
:param aliases: Aliases for the resulting index.
: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: Configuration options for the target index.
: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: The number of shard copies that must be active
before proceeding with the operation. Set to `all` or any positive integer
up to the total number of shards in the index (`number_of_replicas+1`).
"""
if index in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'index'")
if target in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'target'")
__path_parts: t.Dict[str, str] = {
"index": _quote(index),
"target": _quote(target),
}
__path = f'/{__path_parts["index"]}/_clone/{__path_parts["target"]}'
__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 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 not __body:
if aliases is not None:
__body["aliases"] = aliases
if settings is not None:
__body["settings"] = settings
if not __body:
__body = None # type: ignore[assignment]
__headers = {"accept": "application/json"}
if __body is not None:
__headers["content-type"] = "application/json"
return await self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="indices.clone",
path_parts=__path_parts,
)
@_rewrite_parameters()
async def close(
self,
*,
index: t.Union[str, t.Sequence[str]],
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,
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,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Close an index.
A closed index is blocked for read or write operations and does not allow all operations that opened indices allow.
It is not possible to index documents or to search for documents in a closed index.
Closed indices do not have to maintain internal data structures for indexing or searching documents, which results in a smaller overhead on the cluster.</p>
<p>When opening or closing an index, the master node is responsible for restarting the index shards to reflect the new state of the index.
The shards will then go through the normal recovery process.
The data of opened and closed indices is automatically replicated by the cluster to ensure that enough shard copies are safely kept around at all times.</p>
<p>You can open and close multiple indices.
An error is thrown if the request explicitly refers to a missing index.
This behaviour can be turned off using the <code>ignore_unavailable=true</code> parameter.</p>
<p>By default, you must explicitly name the indices you are opening or closing.
To open or close indices with <code>_all</code>, <code>*</code>, or other wildcard expressions, change the<code> action.destructive_requires_name</code> setting to <code>false</code>. This setting can also be changed with the cluster update settings API.</p>
<p>Closed indices consume a significant amount of disk-space which can cause problems in managed environments.
Closing indices can be turned off with the cluster settings API by setting <code>cluster.indices.close.enable</code> to <code>false</code>.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/indices-close.html>`_
:param index: Comma-separated list or wildcard expression of index names used
to limit the request.
:param allow_no_indices: If `false`, the request returns an error if any wildcard
expression, index alias, or `_all` value targets only missing or closed indices.
This behavior applies even if the request targets other open indices.
:param expand_wildcards: Type of index that wildcard patterns can match. If the
request can target data streams, this argument determines whether wildcard
expressions match hidden data streams. Supports comma-separated values, such
as `open,hidden`. Valid values are: `all`, `open`, `closed`, `hidden`, `none`.
:param ignore_unavailable: If `false`, the request returns an error if it targets
a missing or closed index.
: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: The number of shard copies that must be active
before proceeding with the operation. Set to `all` or any positive integer
up to the total number of shards in the index (`number_of_replicas+1`).
"""
if index in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'index'")
__path_parts: t.Dict[str, str] = {"index": _quote(index)}
__path = f'/{__path_parts["index"]}/_close'
__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 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
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"POST",
__path,
params=__query,
headers=__headers,
endpoint_id="indices.close",
path_parts=__path_parts,
)
@_rewrite_parameters(
body_fields=("aliases", "mappings", "settings"),
)
async def create(
self,
*,
index: str,
aliases: t.Optional[t.Mapping[str, t.Mapping[str, t.Any]]] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None,
human: t.Optional[bool] = None,
mappings: 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,
settings: t.Optional[t.Mapping[str, t.Any]] = 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,
body: t.Optional[t.Dict[str, t.Any]] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Create an index.
You can use the create index API to add a new index to an Elasticsearch cluster.
When creating an index, you can specify the following:</p>
<ul>
<li>Settings for the index.</li>
<li>Mappings for fields in the index.</li>
<li>Index aliases</li>
</ul>
<p><strong>Wait for active shards</strong></p>
<p>By default, index creation will only return a response to the client when the primary copies of each shard have been started, or the request times out.
The index creation response will indicate what happened.
For example, <code>acknowledged</code> indicates whether the index was successfully created in the cluster, <code>while shards_acknowledged</code> indicates whether the requisite number of shard copies were started for each shard in the index before timing out.
Note that it is still possible for either <code>acknowledged</code> or <code>shards_acknowledged</code> to be <code>false</code>, but for the index creation to be successful.
These values simply indicate whether the operation completed before the timeout.
If <code>acknowledged</code> is false, the request timed out before the cluster state was updated with the newly created index, but it probably will be created sometime soon.
If <code>shards_acknowledged</code> is false, then the request timed out before the requisite number of shards were started (by default just the primaries), even if the cluster state was successfully updated to reflect the newly created index (that is to say, <code>acknowledged</code> is <code>true</code>).</p>
<p>You can change the default of only waiting for the primary shards to start through the index setting <code>index.write.wait_for_active_shards</code>.
Note that changing this setting will also affect the <code>wait_for_active_shards</code> value on all subsequent write operations.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/indices-create-index.html>`_
:param index: Name of the index you wish to create.
:param aliases: Aliases for the index.
:param mappings: Mapping for fields in the index. If specified, this mapping
can include: - Field names - Field data types - Mapping parameters
: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: Configuration options for the index.
: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: The number of shard copies that must be active
before proceeding with the operation. Set to `all` or any positive integer
up to the total number of shards in the index (`number_of_replicas+1`).
"""
if index in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'index'")
__path_parts: t.Dict[str, str] = {"index": _quote(index)}
__path = f'/{__path_parts["index"]}'
__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 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 not __body:
if aliases is not None:
__body["aliases"] = aliases
if mappings is not None:
__body["mappings"] = mappings
if settings is not None:
__body["settings"] = settings
if not __body:
__body = None # type: ignore[assignment]
__headers = {"accept": "application/json"}
if __body is not None:
__headers["content-type"] = "application/json"
return await self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="indices.create",
path_parts=__path_parts,
)
@_rewrite_parameters()
async def create_data_stream(
self,
*,
name: 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>Create a data stream.
Creates a data stream.
You must have a matching index template with data stream enabled.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/data-streams.html>`_
:param name: Name of the data stream, which must meet the following criteria:
Lowercase only; Cannot include `\\`, `/`, `*`, `?`, `"`, `<`, `>`, `|`, `,`,
`#`, `:`, or a space character; Cannot start with `-`, `_`, `+`, or `.ds-`;
Cannot be `.` or `..`; Cannot be longer than 255 bytes. Multi-byte characters
count towards this limit faster.
: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'/_data_stream/{__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 await self.perform_request( # type: ignore[return-value]
"PUT",
__path,
params=__query,
headers=__headers,
endpoint_id="indices.create_data_stream",
path_parts=__path_parts,
)
@_rewrite_parameters()
async def data_streams_stats(
self,
*,
name: t.Optional[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,
pretty: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
"""
.. raw:: html
<p>Get data stream stats.
Retrieves statistics for one or more data streams.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/data-streams.html>`_
:param name: Comma-separated list of data streams used to limit the request.
Wildcard expressions (`*`) are supported. To target all data streams in a
cluster, omit this parameter or use `*`.
:param expand_wildcards: Type of data stream that wildcard patterns can match.
Supports comma-separated values, such as `open,hidden`.
"""
__path_parts: t.Dict[str, str]
if name not in SKIP_IN_PATH:
__path_parts = {"name": _quote(name)}
__path = f'/_data_stream/{__path_parts["name"]}/_stats'
else:
__path_parts = {}
__path = "/_data_stream/_stats"
__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 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="indices.data_streams_stats",
path_parts=__path_parts,
)
@_rewrite_parameters()
async def delete(
self,
*,
index: t.Union[str, t.Sequence[str]],
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,
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 indices.
Deleting an index deletes its documents, shards, and metadata.
It does not delete related Kibana components, such as data views, visualizations, or dashboards.</p>
<p>You cannot delete the current write index of a data stream.
To delete the index, you must roll over the data stream so a new write index is created.
You can then use the delete index API to delete the previous write index.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/indices-delete-index.html>`_
:param index: Comma-separated list of indices to delete. You cannot specify index
aliases. By default, this parameter does not support wildcards (`*`) or `_all`.
To use wildcards or `_all`, set the `action.destructive_requires_name` cluster
setting to `false`.
:param allow_no_indices: If `false`, the request returns an error if any wildcard
expression, index alias, or `_all` value targets only missing or closed indices.
This behavior applies even if the request targets other open indices.
:param expand_wildcards: Type of index that wildcard patterns can match. If the
request can target data streams, this argument determines whether wildcard
expressions match hidden data streams. Supports comma-separated values, such
as `open,hidden`. Valid values are: `all`, `open`, `closed`, `hidden`, `none`.
:param ignore_unavailable: If `false`, the request returns an error if it targets
a missing or closed index.
: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 index in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'index'")
__path_parts: t.Dict[str, str] = {"index": _quote(index)}
__path = f'/{__path_parts["index"]}'
__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 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 await self.perform_request( # type: ignore[return-value]
"DELETE",
__path,
params=__query,
headers=__headers,
endpoint_id="indices.delete",
path_parts=__path_parts,
)
@_rewrite_parameters()
async def delete_alias(
self,
*,
index: t.Union[str, t.Sequence[str]],
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 an alias.
Removes a data stream or index from an alias.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/indices-delete-alias.html>`_
:param index: Comma-separated list of data streams or indices used to limit the
request. Supports wildcards (`*`).
:param name: Comma-separated list of aliases to remove. Supports wildcards (`*`).
To remove all aliases, use `*` or `_all`.
: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 index in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'index'")
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
__path_parts: t.Dict[str, str] = {"index": _quote(index), "name": _quote(name)}
__path = f'/{__path_parts["index"]}/_alias/{__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 await self.perform_request( # type: ignore[return-value]
"DELETE",
__path,
params=__query,
headers=__headers,
endpoint_id="indices.delete_alias",
path_parts=__path_parts,
)
@_rewrite_parameters()
async def delete_data_lifecycle(
self,
*,
name: t.Union[str, t.Sequence[str]],
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,
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 data stream lifecycles.
Removes the data stream lifecycle from a data stream, rendering it not managed by the data stream lifecycle.</p>
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.17/data-streams-delete-lifecycle.html>`_
:param name: A comma-separated list of data streams of which the data stream
lifecycle will be deleted; use `*` to get all data streams
:param expand_wildcards: Whether wildcard expressions should get expanded to
open or closed indices (default: open)
:param master_timeout: Specify timeout for connection to master
:param timeout: Explicit timestamp for the document
"""
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'/_data_stream/{__path_parts["name"]}/_lifecycle'
__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 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 await self.perform_request( # type: ignore[return-value]
"DELETE",
__path,
params=__query,
headers=__headers,
endpoint_id="indices.delete_data_lifecycle",
path_parts=__path_parts,
)
@_rewrite_parameters()
async def delete_data_stream(
self,
*,
name: t.Union[str, t.Sequence[str]],
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,