elasticsearch 8.17.1__py3-none-any.whl → 8.18.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. elasticsearch/__init__.py +2 -2
  2. elasticsearch/_async/client/__init__.py +2146 -859
  3. elasticsearch/_async/client/_base.py +0 -1
  4. elasticsearch/_async/client/async_search.py +44 -29
  5. elasticsearch/_async/client/autoscaling.py +32 -26
  6. elasticsearch/_async/client/cat.py +244 -169
  7. elasticsearch/_async/client/ccr.py +268 -128
  8. elasticsearch/_async/client/cluster.py +191 -164
  9. elasticsearch/_async/client/connector.py +212 -116
  10. elasticsearch/_async/client/dangling_indices.py +22 -16
  11. elasticsearch/_async/client/enrich.py +51 -11
  12. elasticsearch/_async/client/eql.py +54 -13
  13. elasticsearch/_async/client/esql.py +352 -4
  14. elasticsearch/_async/client/features.py +37 -27
  15. elasticsearch/_async/client/fleet.py +22 -10
  16. elasticsearch/_async/client/graph.py +10 -9
  17. elasticsearch/_async/client/ilm.py +108 -77
  18. elasticsearch/_async/client/indices.py +1112 -677
  19. elasticsearch/_async/client/inference.py +1875 -133
  20. elasticsearch/_async/client/ingest.py +83 -50
  21. elasticsearch/_async/client/license.py +90 -38
  22. elasticsearch/_async/client/logstash.py +20 -9
  23. elasticsearch/_async/client/migration.py +26 -17
  24. elasticsearch/_async/client/ml.py +642 -365
  25. elasticsearch/_async/client/monitoring.py +6 -3
  26. elasticsearch/_async/client/nodes.py +51 -53
  27. elasticsearch/_async/client/query_rules.py +59 -33
  28. elasticsearch/_async/client/rollup.py +124 -86
  29. elasticsearch/_async/client/search_application.py +60 -32
  30. elasticsearch/_async/client/searchable_snapshots.py +25 -12
  31. elasticsearch/_async/client/security.py +896 -558
  32. elasticsearch/_async/client/shutdown.py +34 -36
  33. elasticsearch/_async/client/simulate.py +22 -28
  34. elasticsearch/_async/client/slm.py +65 -40
  35. elasticsearch/_async/client/snapshot.py +190 -213
  36. elasticsearch/_async/client/sql.py +43 -22
  37. elasticsearch/_async/client/ssl.py +17 -18
  38. elasticsearch/_async/client/synonyms.py +58 -37
  39. elasticsearch/_async/client/tasks.py +77 -48
  40. elasticsearch/_async/client/text_structure.py +65 -56
  41. elasticsearch/_async/client/transform.py +124 -93
  42. elasticsearch/_async/client/watcher.py +116 -72
  43. elasticsearch/_async/client/xpack.py +18 -9
  44. elasticsearch/_async/helpers.py +1 -2
  45. elasticsearch/_sync/client/__init__.py +2146 -859
  46. elasticsearch/_sync/client/_base.py +0 -1
  47. elasticsearch/_sync/client/async_search.py +44 -29
  48. elasticsearch/_sync/client/autoscaling.py +32 -26
  49. elasticsearch/_sync/client/cat.py +244 -169
  50. elasticsearch/_sync/client/ccr.py +268 -128
  51. elasticsearch/_sync/client/cluster.py +191 -164
  52. elasticsearch/_sync/client/connector.py +212 -116
  53. elasticsearch/_sync/client/dangling_indices.py +22 -16
  54. elasticsearch/_sync/client/enrich.py +51 -11
  55. elasticsearch/_sync/client/eql.py +54 -13
  56. elasticsearch/_sync/client/esql.py +352 -4
  57. elasticsearch/_sync/client/features.py +37 -27
  58. elasticsearch/_sync/client/fleet.py +22 -10
  59. elasticsearch/_sync/client/graph.py +10 -9
  60. elasticsearch/_sync/client/ilm.py +108 -77
  61. elasticsearch/_sync/client/indices.py +1112 -677
  62. elasticsearch/_sync/client/inference.py +1875 -133
  63. elasticsearch/_sync/client/ingest.py +83 -50
  64. elasticsearch/_sync/client/license.py +90 -38
  65. elasticsearch/_sync/client/logstash.py +20 -9
  66. elasticsearch/_sync/client/migration.py +26 -17
  67. elasticsearch/_sync/client/ml.py +642 -365
  68. elasticsearch/_sync/client/monitoring.py +6 -3
  69. elasticsearch/_sync/client/nodes.py +51 -53
  70. elasticsearch/_sync/client/query_rules.py +59 -33
  71. elasticsearch/_sync/client/rollup.py +124 -86
  72. elasticsearch/_sync/client/search_application.py +60 -32
  73. elasticsearch/_sync/client/searchable_snapshots.py +25 -12
  74. elasticsearch/_sync/client/security.py +896 -558
  75. elasticsearch/_sync/client/shutdown.py +34 -36
  76. elasticsearch/_sync/client/simulate.py +22 -28
  77. elasticsearch/_sync/client/slm.py +65 -40
  78. elasticsearch/_sync/client/snapshot.py +190 -213
  79. elasticsearch/_sync/client/sql.py +43 -22
  80. elasticsearch/_sync/client/ssl.py +17 -18
  81. elasticsearch/_sync/client/synonyms.py +58 -37
  82. elasticsearch/_sync/client/tasks.py +77 -48
  83. elasticsearch/_sync/client/text_structure.py +65 -56
  84. elasticsearch/_sync/client/transform.py +124 -93
  85. elasticsearch/_sync/client/utils.py +1 -4
  86. elasticsearch/_sync/client/watcher.py +116 -72
  87. elasticsearch/_sync/client/xpack.py +18 -9
  88. elasticsearch/_version.py +1 -1
  89. elasticsearch/client.py +2 -0
  90. elasticsearch/dsl/__init__.py +203 -0
  91. elasticsearch/dsl/_async/__init__.py +16 -0
  92. elasticsearch/dsl/_async/document.py +522 -0
  93. elasticsearch/dsl/_async/faceted_search.py +50 -0
  94. elasticsearch/dsl/_async/index.py +639 -0
  95. elasticsearch/dsl/_async/mapping.py +49 -0
  96. elasticsearch/dsl/_async/search.py +233 -0
  97. elasticsearch/dsl/_async/update_by_query.py +47 -0
  98. elasticsearch/dsl/_sync/__init__.py +16 -0
  99. elasticsearch/dsl/_sync/document.py +514 -0
  100. elasticsearch/dsl/_sync/faceted_search.py +50 -0
  101. elasticsearch/dsl/_sync/index.py +597 -0
  102. elasticsearch/dsl/_sync/mapping.py +49 -0
  103. elasticsearch/dsl/_sync/search.py +226 -0
  104. elasticsearch/dsl/_sync/update_by_query.py +45 -0
  105. elasticsearch/dsl/aggs.py +3730 -0
  106. elasticsearch/dsl/analysis.py +341 -0
  107. elasticsearch/dsl/async_connections.py +37 -0
  108. elasticsearch/dsl/connections.py +142 -0
  109. elasticsearch/dsl/document.py +20 -0
  110. elasticsearch/dsl/document_base.py +444 -0
  111. elasticsearch/dsl/exceptions.py +32 -0
  112. elasticsearch/dsl/faceted_search.py +28 -0
  113. elasticsearch/dsl/faceted_search_base.py +489 -0
  114. elasticsearch/dsl/field.py +4254 -0
  115. elasticsearch/dsl/function.py +180 -0
  116. elasticsearch/dsl/index.py +23 -0
  117. elasticsearch/dsl/index_base.py +178 -0
  118. elasticsearch/dsl/mapping.py +19 -0
  119. elasticsearch/dsl/mapping_base.py +219 -0
  120. elasticsearch/dsl/query.py +2816 -0
  121. elasticsearch/dsl/response/__init__.py +388 -0
  122. elasticsearch/dsl/response/aggs.py +100 -0
  123. elasticsearch/dsl/response/hit.py +53 -0
  124. elasticsearch/dsl/search.py +20 -0
  125. elasticsearch/dsl/search_base.py +1040 -0
  126. elasticsearch/dsl/serializer.py +34 -0
  127. elasticsearch/dsl/types.py +6471 -0
  128. elasticsearch/dsl/update_by_query.py +19 -0
  129. elasticsearch/dsl/update_by_query_base.py +149 -0
  130. elasticsearch/dsl/utils.py +687 -0
  131. elasticsearch/dsl/wrappers.py +119 -0
  132. elasticsearch/helpers/actions.py +1 -1
  133. elasticsearch/helpers/vectorstore/_sync/vectorstore.py +4 -1
  134. {elasticsearch-8.17.1.dist-info → elasticsearch-8.18.0.dist-info}/METADATA +12 -2
  135. elasticsearch-8.18.0.dist-info/RECORD +161 -0
  136. elasticsearch-8.17.1.dist-info/RECORD +0 -119
  137. {elasticsearch-8.17.1.dist-info → elasticsearch-8.18.0.dist-info}/WHEEL +0 -0
  138. {elasticsearch-8.17.1.dist-info → elasticsearch-8.18.0.dist-info}/licenses/LICENSE +0 -0
  139. {elasticsearch-8.17.1.dist-info → elasticsearch-8.18.0.dist-info}/licenses/NOTICE +0 -0
@@ -0,0 +1,639 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ from typing import TYPE_CHECKING, Any, Dict, Optional
19
+
20
+ from typing_extensions import Self
21
+
22
+ from ..async_connections import get_connection
23
+ from ..exceptions import IllegalOperation
24
+ from ..index_base import IndexBase
25
+ from ..utils import AsyncUsingType
26
+ from .mapping import AsyncMapping
27
+ from .search import AsyncSearch
28
+ from .update_by_query import AsyncUpdateByQuery
29
+
30
+ if TYPE_CHECKING:
31
+ from elastic_transport import ObjectApiResponse
32
+
33
+ from elasticsearch import AsyncElasticsearch
34
+
35
+
36
+ class AsyncIndexTemplate:
37
+ def __init__(
38
+ self,
39
+ name: str,
40
+ template: str,
41
+ index: Optional["AsyncIndex"] = None,
42
+ order: Optional[int] = None,
43
+ **kwargs: Any,
44
+ ):
45
+ if index is None:
46
+ self._index = AsyncIndex(template, **kwargs)
47
+ else:
48
+ if kwargs:
49
+ raise ValueError(
50
+ "You cannot specify options for Index when"
51
+ " passing an Index instance."
52
+ )
53
+ self._index = index.clone()
54
+ self._index._name = template
55
+ self._template_name = name
56
+ self.order = order
57
+
58
+ def __getattr__(self, attr_name: str) -> Any:
59
+ return getattr(self._index, attr_name)
60
+
61
+ def to_dict(self) -> Dict[str, Any]:
62
+ d = self._index.to_dict()
63
+ d["index_patterns"] = [self._index._name]
64
+ if self.order is not None:
65
+ d["order"] = self.order
66
+ return d
67
+
68
+ async def save(
69
+ self, using: Optional[AsyncUsingType] = None
70
+ ) -> "ObjectApiResponse[Any]":
71
+ es = get_connection(using or self._index._using)
72
+ return await es.indices.put_template(
73
+ name=self._template_name, body=self.to_dict()
74
+ )
75
+
76
+
77
+ class AsyncComposableIndexTemplate:
78
+ def __init__(
79
+ self,
80
+ name: str,
81
+ template: str,
82
+ index: Optional["AsyncIndex"] = None,
83
+ priority: Optional[int] = None,
84
+ **kwargs: Any,
85
+ ):
86
+ if index is None:
87
+ self._index = AsyncIndex(template, **kwargs)
88
+ else:
89
+ if kwargs:
90
+ raise ValueError(
91
+ "You cannot specify options for Index when"
92
+ " passing an Index instance."
93
+ )
94
+ self._index = index.clone()
95
+ self._index._name = template
96
+ self._template_name = name
97
+ self.priority = priority
98
+
99
+ def __getattr__(self, attr_name: str) -> Any:
100
+ return getattr(self._index, attr_name)
101
+
102
+ def to_dict(self) -> Dict[str, Any]:
103
+ d: Dict[str, Any] = {"template": self._index.to_dict()}
104
+ d["index_patterns"] = [self._index._name]
105
+ if self.priority is not None:
106
+ d["priority"] = self.priority
107
+ return d
108
+
109
+ async def save(
110
+ self, using: Optional[AsyncUsingType] = None
111
+ ) -> "ObjectApiResponse[Any]":
112
+ es = get_connection(using or self._index._using)
113
+ return await es.indices.put_index_template(
114
+ name=self._template_name, **self.to_dict()
115
+ )
116
+
117
+
118
+ class AsyncIndex(IndexBase):
119
+ _using: AsyncUsingType
120
+
121
+ if TYPE_CHECKING:
122
+
123
+ def get_or_create_mapping(self) -> AsyncMapping: ...
124
+
125
+ def __init__(self, name: str, using: AsyncUsingType = "default"):
126
+ """
127
+ :arg name: name of the index
128
+ :arg using: connection alias to use, defaults to ``'default'``
129
+ """
130
+ super().__init__(name, AsyncMapping, using=using)
131
+
132
+ def _get_connection(
133
+ self, using: Optional[AsyncUsingType] = None
134
+ ) -> "AsyncElasticsearch":
135
+ if self._name is None:
136
+ raise ValueError("You cannot perform API calls on the default index.")
137
+ return get_connection(using or self._using)
138
+
139
+ connection = property(_get_connection)
140
+
141
+ def as_template(
142
+ self,
143
+ template_name: str,
144
+ pattern: Optional[str] = None,
145
+ order: Optional[int] = None,
146
+ ) -> AsyncIndexTemplate:
147
+ return AsyncIndexTemplate(
148
+ template_name, pattern or self._name, index=self, order=order
149
+ )
150
+
151
+ def as_composable_template(
152
+ self,
153
+ template_name: str,
154
+ pattern: Optional[str] = None,
155
+ priority: Optional[int] = None,
156
+ ) -> AsyncComposableIndexTemplate:
157
+ return AsyncComposableIndexTemplate(
158
+ template_name, pattern or self._name, index=self, priority=priority
159
+ )
160
+
161
+ async def load_mappings(self, using: Optional[AsyncUsingType] = None) -> None:
162
+ await self.get_or_create_mapping().update_from_es(
163
+ self._name, using=using or self._using
164
+ )
165
+
166
+ def clone(
167
+ self, name: Optional[str] = None, using: Optional[AsyncUsingType] = None
168
+ ) -> Self:
169
+ """
170
+ Create a copy of the instance with another name or connection alias.
171
+ Useful for creating multiple indices with shared configuration::
172
+
173
+ i = Index('base-index')
174
+ i.settings(number_of_shards=1)
175
+ i.create()
176
+
177
+ i2 = i.clone('other-index')
178
+ i2.create()
179
+
180
+ :arg name: name of the index
181
+ :arg using: connection alias to use, defaults to ``'default'``
182
+ """
183
+ i = self.__class__(name or self._name, using=using or self._using)
184
+ i._settings = self._settings.copy()
185
+ i._aliases = self._aliases.copy()
186
+ i._analysis = self._analysis.copy()
187
+ i._doc_types = self._doc_types[:]
188
+ if self._mapping is not None:
189
+ i._mapping = self._mapping._clone()
190
+ return i
191
+
192
+ def search(self, using: Optional[AsyncUsingType] = None) -> AsyncSearch:
193
+ """
194
+ Return a :class:`~elasticsearch.dsl.Search` object searching over the
195
+ index (or all the indices belonging to this template) and its
196
+ ``Document``\\s.
197
+ """
198
+ return AsyncSearch(
199
+ using=using or self._using, index=self._name, doc_type=self._doc_types
200
+ )
201
+
202
+ def updateByQuery(
203
+ self, using: Optional[AsyncUsingType] = None
204
+ ) -> AsyncUpdateByQuery:
205
+ """
206
+ Return a :class:`~elasticsearch.dsl.UpdateByQuery` object searching over the index
207
+ (or all the indices belonging to this template) and updating Documents that match
208
+ the search criteria.
209
+
210
+ For more information, see here:
211
+ https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html
212
+ """
213
+ return AsyncUpdateByQuery(
214
+ using=using or self._using,
215
+ index=self._name,
216
+ )
217
+
218
+ async def create(
219
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
220
+ ) -> "ObjectApiResponse[Any]":
221
+ """
222
+ Creates the index in elasticsearch.
223
+
224
+ Any additional keyword arguments will be passed to
225
+ ``Elasticsearch.indices.create`` unchanged.
226
+ """
227
+ return await self._get_connection(using).indices.create(
228
+ index=self._name, body=self.to_dict(), **kwargs
229
+ )
230
+
231
+ async def is_closed(self, using: Optional[AsyncUsingType] = None) -> bool:
232
+ state = await self._get_connection(using).cluster.state(
233
+ index=self._name, metric="metadata"
234
+ )
235
+ return bool(state["metadata"]["indices"][self._name]["state"] == "close")
236
+
237
+ async def save(
238
+ self, using: Optional[AsyncUsingType] = None
239
+ ) -> "Optional[ObjectApiResponse[Any]]":
240
+ """
241
+ Sync the index definition with elasticsearch, creating the index if it
242
+ doesn't exist and updating its settings and mappings if it does.
243
+
244
+ Note some settings and mapping changes cannot be done on an open
245
+ index (or at all on an existing index) and for those this method will
246
+ fail with the underlying exception.
247
+ """
248
+ if not await self.exists(using=using):
249
+ return await self.create(using=using)
250
+
251
+ body = self.to_dict()
252
+ settings = body.pop("settings", {})
253
+ analysis = settings.pop("analysis", None)
254
+ current_settings = (await self.get_settings(using=using))[self._name][
255
+ "settings"
256
+ ]["index"]
257
+ if analysis:
258
+ if await self.is_closed(using=using):
259
+ # closed index, update away
260
+ settings["analysis"] = analysis
261
+ else:
262
+ # compare analysis definition, if all analysis objects are
263
+ # already defined as requested, skip analysis update and
264
+ # proceed, otherwise raise IllegalOperation
265
+ existing_analysis = current_settings.get("analysis", {})
266
+ if any(
267
+ existing_analysis.get(section, {}).get(k, None)
268
+ != analysis[section][k]
269
+ for section in analysis
270
+ for k in analysis[section]
271
+ ):
272
+ raise IllegalOperation(
273
+ "You cannot update analysis configuration on an open index, "
274
+ "you need to close index %s first." % self._name
275
+ )
276
+
277
+ # try and update the settings
278
+ if settings:
279
+ settings = settings.copy()
280
+ for k, v in list(settings.items()):
281
+ if k in current_settings and current_settings[k] == str(v):
282
+ del settings[k]
283
+
284
+ if settings:
285
+ await self.put_settings(using=using, body=settings)
286
+
287
+ # update the mappings, any conflict in the mappings will result in an
288
+ # exception
289
+ mappings = body.pop("mappings", {})
290
+ if mappings:
291
+ return await self.put_mapping(using=using, body=mappings)
292
+
293
+ return None
294
+
295
+ async def analyze(
296
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
297
+ ) -> "ObjectApiResponse[Any]":
298
+ """
299
+ Perform the analysis process on a text and return the tokens breakdown
300
+ of the text.
301
+
302
+ Any additional keyword arguments will be passed to
303
+ ``Elasticsearch.indices.analyze`` unchanged.
304
+ """
305
+ return await self._get_connection(using).indices.analyze(
306
+ index=self._name, **kwargs
307
+ )
308
+
309
+ async def refresh(
310
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
311
+ ) -> "ObjectApiResponse[Any]":
312
+ """
313
+ Performs a refresh operation on the index.
314
+
315
+ Any additional keyword arguments will be passed to
316
+ ``Elasticsearch.indices.refresh`` unchanged.
317
+ """
318
+ return await self._get_connection(using).indices.refresh(
319
+ index=self._name, **kwargs
320
+ )
321
+
322
+ async def flush(
323
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
324
+ ) -> "ObjectApiResponse[Any]":
325
+ """
326
+ Performs a flush operation on the index.
327
+
328
+ Any additional keyword arguments will be passed to
329
+ ``Elasticsearch.indices.flush`` unchanged.
330
+ """
331
+ return await self._get_connection(using).indices.flush(
332
+ index=self._name, **kwargs
333
+ )
334
+
335
+ async def get(
336
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
337
+ ) -> "ObjectApiResponse[Any]":
338
+ """
339
+ The get index API allows to retrieve information about the index.
340
+
341
+ Any additional keyword arguments will be passed to
342
+ ``Elasticsearch.indices.get`` unchanged.
343
+ """
344
+ return await self._get_connection(using).indices.get(index=self._name, **kwargs)
345
+
346
+ async def open(
347
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
348
+ ) -> "ObjectApiResponse[Any]":
349
+ """
350
+ Opens the index in elasticsearch.
351
+
352
+ Any additional keyword arguments will be passed to
353
+ ``Elasticsearch.indices.open`` unchanged.
354
+ """
355
+ return await self._get_connection(using).indices.open(
356
+ index=self._name, **kwargs
357
+ )
358
+
359
+ async def close(
360
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
361
+ ) -> "ObjectApiResponse[Any]":
362
+ """
363
+ Closes the index in elasticsearch.
364
+
365
+ Any additional keyword arguments will be passed to
366
+ ``Elasticsearch.indices.close`` unchanged.
367
+ """
368
+ return await self._get_connection(using).indices.close(
369
+ index=self._name, **kwargs
370
+ )
371
+
372
+ async def delete(
373
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
374
+ ) -> "ObjectApiResponse[Any]":
375
+ """
376
+ Deletes the index in elasticsearch.
377
+
378
+ Any additional keyword arguments will be passed to
379
+ ``Elasticsearch.indices.delete`` unchanged.
380
+ """
381
+ return await self._get_connection(using).indices.delete(
382
+ index=self._name, **kwargs
383
+ )
384
+
385
+ async def exists(
386
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
387
+ ) -> bool:
388
+ """
389
+ Returns ``True`` if the index already exists in elasticsearch.
390
+
391
+ Any additional keyword arguments will be passed to
392
+ ``Elasticsearch.indices.exists`` unchanged.
393
+ """
394
+ return bool(
395
+ await self._get_connection(using).indices.exists(index=self._name, **kwargs)
396
+ )
397
+
398
+ async def put_mapping(
399
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
400
+ ) -> "ObjectApiResponse[Any]":
401
+ """
402
+ Register specific mapping definition for a specific type.
403
+
404
+ Any additional keyword arguments will be passed to
405
+ ``Elasticsearch.indices.put_mapping`` unchanged.
406
+ """
407
+ return await self._get_connection(using).indices.put_mapping(
408
+ index=self._name, **kwargs
409
+ )
410
+
411
+ async def get_mapping(
412
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
413
+ ) -> "ObjectApiResponse[Any]":
414
+ """
415
+ Retrieve specific mapping definition for a specific type.
416
+
417
+ Any additional keyword arguments will be passed to
418
+ ``Elasticsearch.indices.get_mapping`` unchanged.
419
+ """
420
+ return await self._get_connection(using).indices.get_mapping(
421
+ index=self._name, **kwargs
422
+ )
423
+
424
+ async def get_field_mapping(
425
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
426
+ ) -> "ObjectApiResponse[Any]":
427
+ """
428
+ Retrieve mapping definition of a specific field.
429
+
430
+ Any additional keyword arguments will be passed to
431
+ ``Elasticsearch.indices.get_field_mapping`` unchanged.
432
+ """
433
+ return await self._get_connection(using).indices.get_field_mapping(
434
+ index=self._name, **kwargs
435
+ )
436
+
437
+ async def put_alias(
438
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
439
+ ) -> "ObjectApiResponse[Any]":
440
+ """
441
+ Create an alias for the index.
442
+
443
+ Any additional keyword arguments will be passed to
444
+ ``Elasticsearch.indices.put_alias`` unchanged.
445
+ """
446
+ return await self._get_connection(using).indices.put_alias(
447
+ index=self._name, **kwargs
448
+ )
449
+
450
+ async def exists_alias(
451
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
452
+ ) -> bool:
453
+ """
454
+ Return a boolean indicating whether given alias exists for this index.
455
+
456
+ Any additional keyword arguments will be passed to
457
+ ``Elasticsearch.indices.exists_alias`` unchanged.
458
+ """
459
+ return bool(
460
+ await self._get_connection(using).indices.exists_alias(
461
+ index=self._name, **kwargs
462
+ )
463
+ )
464
+
465
+ async def get_alias(
466
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
467
+ ) -> "ObjectApiResponse[Any]":
468
+ """
469
+ Retrieve a specified alias.
470
+
471
+ Any additional keyword arguments will be passed to
472
+ ``Elasticsearch.indices.get_alias`` unchanged.
473
+ """
474
+ return await self._get_connection(using).indices.get_alias(
475
+ index=self._name, **kwargs
476
+ )
477
+
478
+ async def delete_alias(
479
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
480
+ ) -> "ObjectApiResponse[Any]":
481
+ """
482
+ Delete specific alias.
483
+
484
+ Any additional keyword arguments will be passed to
485
+ ``Elasticsearch.indices.delete_alias`` unchanged.
486
+ """
487
+ return await self._get_connection(using).indices.delete_alias(
488
+ index=self._name, **kwargs
489
+ )
490
+
491
+ async def get_settings(
492
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
493
+ ) -> "ObjectApiResponse[Any]":
494
+ """
495
+ Retrieve settings for the index.
496
+
497
+ Any additional keyword arguments will be passed to
498
+ ``Elasticsearch.indices.get_settings`` unchanged.
499
+ """
500
+ return await self._get_connection(using).indices.get_settings(
501
+ index=self._name, **kwargs
502
+ )
503
+
504
+ async def put_settings(
505
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
506
+ ) -> "ObjectApiResponse[Any]":
507
+ """
508
+ Change specific index level settings in real time.
509
+
510
+ Any additional keyword arguments will be passed to
511
+ ``Elasticsearch.indices.put_settings`` unchanged.
512
+ """
513
+ return await self._get_connection(using).indices.put_settings(
514
+ index=self._name, **kwargs
515
+ )
516
+
517
+ async def stats(
518
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
519
+ ) -> "ObjectApiResponse[Any]":
520
+ """
521
+ Retrieve statistics on different operations happening on the index.
522
+
523
+ Any additional keyword arguments will be passed to
524
+ ``Elasticsearch.indices.stats`` unchanged.
525
+ """
526
+ return await self._get_connection(using).indices.stats(
527
+ index=self._name, **kwargs
528
+ )
529
+
530
+ async def segments(
531
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
532
+ ) -> "ObjectApiResponse[Any]":
533
+ """
534
+ Provide low level segments information that a Lucene index (shard
535
+ level) is built with.
536
+
537
+ Any additional keyword arguments will be passed to
538
+ ``Elasticsearch.indices.segments`` unchanged.
539
+ """
540
+ return await self._get_connection(using).indices.segments(
541
+ index=self._name, **kwargs
542
+ )
543
+
544
+ async def validate_query(
545
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
546
+ ) -> "ObjectApiResponse[Any]":
547
+ """
548
+ Validate a potentially expensive query without executing it.
549
+
550
+ Any additional keyword arguments will be passed to
551
+ ``Elasticsearch.indices.validate_query`` unchanged.
552
+ """
553
+ return await self._get_connection(using).indices.validate_query(
554
+ index=self._name, **kwargs
555
+ )
556
+
557
+ async def clear_cache(
558
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
559
+ ) -> "ObjectApiResponse[Any]":
560
+ """
561
+ Clear all caches or specific cached associated with the index.
562
+
563
+ Any additional keyword arguments will be passed to
564
+ ``Elasticsearch.indices.clear_cache`` unchanged.
565
+ """
566
+ return await self._get_connection(using).indices.clear_cache(
567
+ index=self._name, **kwargs
568
+ )
569
+
570
+ async def recovery(
571
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
572
+ ) -> "ObjectApiResponse[Any]":
573
+ """
574
+ The indices recovery API provides insight into on-going shard
575
+ recoveries for the index.
576
+
577
+ Any additional keyword arguments will be passed to
578
+ ``Elasticsearch.indices.recovery`` unchanged.
579
+ """
580
+ return await self._get_connection(using).indices.recovery(
581
+ index=self._name, **kwargs
582
+ )
583
+
584
+ async def shard_stores(
585
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
586
+ ) -> "ObjectApiResponse[Any]":
587
+ """
588
+ Provides store information for shard copies of the index. Store
589
+ information reports on which nodes shard copies exist, the shard copy
590
+ version, indicating how recent they are, and any exceptions encountered
591
+ while opening the shard index or from earlier engine failure.
592
+
593
+ Any additional keyword arguments will be passed to
594
+ ``Elasticsearch.indices.shard_stores`` unchanged.
595
+ """
596
+ return await self._get_connection(using).indices.shard_stores(
597
+ index=self._name, **kwargs
598
+ )
599
+
600
+ async def forcemerge(
601
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
602
+ ) -> "ObjectApiResponse[Any]":
603
+ """
604
+ The force merge API allows to force merging of the index through an
605
+ API. The merge relates to the number of segments a Lucene index holds
606
+ within each shard. The force merge operation allows to reduce the
607
+ number of segments by merging them.
608
+
609
+ This call will block until the merge is complete. If the http
610
+ connection is lost, the request will continue in the background, and
611
+ any new requests will block until the previous force merge is complete.
612
+
613
+ Any additional keyword arguments will be passed to
614
+ ``Elasticsearch.indices.forcemerge`` unchanged.
615
+ """
616
+ return await self._get_connection(using).indices.forcemerge(
617
+ index=self._name, **kwargs
618
+ )
619
+
620
+ async def shrink(
621
+ self, using: Optional[AsyncUsingType] = None, **kwargs: Any
622
+ ) -> "ObjectApiResponse[Any]":
623
+ """
624
+ The shrink index API allows you to shrink an existing index into a new
625
+ index with fewer primary shards. The number of primary shards in the
626
+ target index must be a factor of the shards in the source index. For
627
+ example an index with 8 primary shards can be shrunk into 4, 2 or 1
628
+ primary shards or an index with 15 primary shards can be shrunk into 5,
629
+ 3 or 1. If the number of shards in the index is a prime number it can
630
+ only be shrunk into a single primary shard. Before shrinking, a
631
+ (primary or replica) copy of every shard in the index must be present
632
+ on the same node.
633
+
634
+ Any additional keyword arguments will be passed to
635
+ ``Elasticsearch.indices.shrink`` unchanged.
636
+ """
637
+ return await self._get_connection(using).indices.shrink(
638
+ index=self._name, **kwargs
639
+ )
@@ -0,0 +1,49 @@
1
+ # Licensed to Elasticsearch B.V. under one or more contributor
2
+ # license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright
4
+ # ownership. Elasticsearch B.V. licenses this file to you under
5
+ # the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ from typing import List, Optional, Union
19
+
20
+ from typing_extensions import Self
21
+
22
+ from ..async_connections import get_connection
23
+ from ..mapping_base import MappingBase
24
+ from ..utils import AsyncUsingType
25
+
26
+
27
+ class AsyncMapping(MappingBase):
28
+ @classmethod
29
+ async def from_es(
30
+ cls, index: Optional[Union[str, List[str]]], using: AsyncUsingType = "default"
31
+ ) -> Self:
32
+ m = cls()
33
+ await m.update_from_es(index, using)
34
+ return m
35
+
36
+ async def update_from_es(
37
+ self, index: Optional[Union[str, List[str]]], using: AsyncUsingType = "default"
38
+ ) -> None:
39
+ es = get_connection(using)
40
+ raw = await es.indices.get_mapping(index=index)
41
+ _, raw = raw.popitem()
42
+ self._update_from_dict(raw["mappings"])
43
+
44
+ async def save(self, index: str, using: AsyncUsingType = "default") -> None:
45
+ from .index import AsyncIndex
46
+
47
+ i = AsyncIndex(index, using=using)
48
+ i.mapping(self)
49
+ await i.save()