elasticsearch 8.17.2__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 (135) hide show
  1. elasticsearch/_async/client/__init__.py +174 -79
  2. elasticsearch/_async/client/_base.py +0 -1
  3. elasticsearch/_async/client/async_search.py +12 -8
  4. elasticsearch/_async/client/autoscaling.py +4 -4
  5. elasticsearch/_async/client/cat.py +26 -26
  6. elasticsearch/_async/client/ccr.py +186 -72
  7. elasticsearch/_async/client/cluster.py +38 -19
  8. elasticsearch/_async/client/connector.py +30 -30
  9. elasticsearch/_async/client/dangling_indices.py +3 -3
  10. elasticsearch/_async/client/enrich.py +26 -5
  11. elasticsearch/_async/client/eql.py +32 -4
  12. elasticsearch/_async/client/esql.py +62 -6
  13. elasticsearch/_async/client/features.py +12 -2
  14. elasticsearch/_async/client/fleet.py +8 -2
  15. elasticsearch/_async/client/graph.py +1 -1
  16. elasticsearch/_async/client/ilm.py +23 -22
  17. elasticsearch/_async/client/indices.py +424 -132
  18. elasticsearch/_async/client/inference.py +1853 -115
  19. elasticsearch/_async/client/ingest.py +32 -38
  20. elasticsearch/_async/client/license.py +51 -16
  21. elasticsearch/_async/client/logstash.py +3 -3
  22. elasticsearch/_async/client/migration.py +3 -3
  23. elasticsearch/_async/client/ml.py +141 -112
  24. elasticsearch/_async/client/monitoring.py +1 -1
  25. elasticsearch/_async/client/nodes.py +9 -27
  26. elasticsearch/_async/client/query_rules.py +8 -8
  27. elasticsearch/_async/client/rollup.py +8 -8
  28. elasticsearch/_async/client/search_application.py +13 -13
  29. elasticsearch/_async/client/searchable_snapshots.py +4 -4
  30. elasticsearch/_async/client/security.py +71 -71
  31. elasticsearch/_async/client/shutdown.py +3 -10
  32. elasticsearch/_async/client/simulate.py +6 -6
  33. elasticsearch/_async/client/slm.py +9 -9
  34. elasticsearch/_async/client/snapshot.py +13 -17
  35. elasticsearch/_async/client/sql.py +6 -6
  36. elasticsearch/_async/client/ssl.py +1 -1
  37. elasticsearch/_async/client/synonyms.py +7 -7
  38. elasticsearch/_async/client/tasks.py +3 -9
  39. elasticsearch/_async/client/text_structure.py +4 -4
  40. elasticsearch/_async/client/transform.py +30 -28
  41. elasticsearch/_async/client/watcher.py +22 -14
  42. elasticsearch/_async/client/xpack.py +2 -2
  43. elasticsearch/_async/helpers.py +0 -1
  44. elasticsearch/_sync/client/__init__.py +174 -79
  45. elasticsearch/_sync/client/_base.py +0 -1
  46. elasticsearch/_sync/client/async_search.py +12 -8
  47. elasticsearch/_sync/client/autoscaling.py +4 -4
  48. elasticsearch/_sync/client/cat.py +26 -26
  49. elasticsearch/_sync/client/ccr.py +186 -72
  50. elasticsearch/_sync/client/cluster.py +38 -19
  51. elasticsearch/_sync/client/connector.py +30 -30
  52. elasticsearch/_sync/client/dangling_indices.py +3 -3
  53. elasticsearch/_sync/client/enrich.py +26 -5
  54. elasticsearch/_sync/client/eql.py +32 -4
  55. elasticsearch/_sync/client/esql.py +62 -6
  56. elasticsearch/_sync/client/features.py +12 -2
  57. elasticsearch/_sync/client/fleet.py +8 -2
  58. elasticsearch/_sync/client/graph.py +1 -1
  59. elasticsearch/_sync/client/ilm.py +23 -22
  60. elasticsearch/_sync/client/indices.py +424 -132
  61. elasticsearch/_sync/client/inference.py +1853 -115
  62. elasticsearch/_sync/client/ingest.py +32 -38
  63. elasticsearch/_sync/client/license.py +51 -16
  64. elasticsearch/_sync/client/logstash.py +3 -3
  65. elasticsearch/_sync/client/migration.py +3 -3
  66. elasticsearch/_sync/client/ml.py +141 -112
  67. elasticsearch/_sync/client/monitoring.py +1 -1
  68. elasticsearch/_sync/client/nodes.py +9 -27
  69. elasticsearch/_sync/client/query_rules.py +8 -8
  70. elasticsearch/_sync/client/rollup.py +8 -8
  71. elasticsearch/_sync/client/search_application.py +13 -13
  72. elasticsearch/_sync/client/searchable_snapshots.py +4 -4
  73. elasticsearch/_sync/client/security.py +71 -71
  74. elasticsearch/_sync/client/shutdown.py +3 -10
  75. elasticsearch/_sync/client/simulate.py +6 -6
  76. elasticsearch/_sync/client/slm.py +9 -9
  77. elasticsearch/_sync/client/snapshot.py +13 -17
  78. elasticsearch/_sync/client/sql.py +6 -6
  79. elasticsearch/_sync/client/ssl.py +1 -1
  80. elasticsearch/_sync/client/synonyms.py +7 -7
  81. elasticsearch/_sync/client/tasks.py +3 -9
  82. elasticsearch/_sync/client/text_structure.py +4 -4
  83. elasticsearch/_sync/client/transform.py +30 -28
  84. elasticsearch/_sync/client/utils.py +0 -3
  85. elasticsearch/_sync/client/watcher.py +22 -14
  86. elasticsearch/_sync/client/xpack.py +2 -2
  87. elasticsearch/_version.py +1 -1
  88. elasticsearch/dsl/__init__.py +203 -0
  89. elasticsearch/dsl/_async/__init__.py +16 -0
  90. elasticsearch/dsl/_async/document.py +522 -0
  91. elasticsearch/dsl/_async/faceted_search.py +50 -0
  92. elasticsearch/dsl/_async/index.py +639 -0
  93. elasticsearch/dsl/_async/mapping.py +49 -0
  94. elasticsearch/dsl/_async/search.py +233 -0
  95. elasticsearch/dsl/_async/update_by_query.py +47 -0
  96. elasticsearch/dsl/_sync/__init__.py +16 -0
  97. elasticsearch/dsl/_sync/document.py +514 -0
  98. elasticsearch/dsl/_sync/faceted_search.py +50 -0
  99. elasticsearch/dsl/_sync/index.py +597 -0
  100. elasticsearch/dsl/_sync/mapping.py +49 -0
  101. elasticsearch/dsl/_sync/search.py +226 -0
  102. elasticsearch/dsl/_sync/update_by_query.py +45 -0
  103. elasticsearch/dsl/aggs.py +3730 -0
  104. elasticsearch/dsl/analysis.py +341 -0
  105. elasticsearch/dsl/async_connections.py +37 -0
  106. elasticsearch/dsl/connections.py +142 -0
  107. elasticsearch/dsl/document.py +20 -0
  108. elasticsearch/dsl/document_base.py +444 -0
  109. elasticsearch/dsl/exceptions.py +32 -0
  110. elasticsearch/dsl/faceted_search.py +28 -0
  111. elasticsearch/dsl/faceted_search_base.py +489 -0
  112. elasticsearch/dsl/field.py +4254 -0
  113. elasticsearch/dsl/function.py +180 -0
  114. elasticsearch/dsl/index.py +23 -0
  115. elasticsearch/dsl/index_base.py +178 -0
  116. elasticsearch/dsl/mapping.py +19 -0
  117. elasticsearch/dsl/mapping_base.py +219 -0
  118. elasticsearch/dsl/query.py +2816 -0
  119. elasticsearch/dsl/response/__init__.py +388 -0
  120. elasticsearch/dsl/response/aggs.py +100 -0
  121. elasticsearch/dsl/response/hit.py +53 -0
  122. elasticsearch/dsl/search.py +20 -0
  123. elasticsearch/dsl/search_base.py +1040 -0
  124. elasticsearch/dsl/serializer.py +34 -0
  125. elasticsearch/dsl/types.py +6471 -0
  126. elasticsearch/dsl/update_by_query.py +19 -0
  127. elasticsearch/dsl/update_by_query_base.py +149 -0
  128. elasticsearch/dsl/utils.py +687 -0
  129. elasticsearch/dsl/wrappers.py +119 -0
  130. {elasticsearch-8.17.2.dist-info → elasticsearch-8.18.0.dist-info}/METADATA +12 -2
  131. elasticsearch-8.18.0.dist-info/RECORD +161 -0
  132. elasticsearch-8.17.2.dist-info/RECORD +0 -119
  133. {elasticsearch-8.17.2.dist-info → elasticsearch-8.18.0.dist-info}/WHEEL +0 -0
  134. {elasticsearch-8.17.2.dist-info → elasticsearch-8.18.0.dist-info}/licenses/LICENSE +0 -0
  135. {elasticsearch-8.17.2.dist-info → elasticsearch-8.18.0.dist-info}/licenses/NOTICE +0 -0
@@ -0,0 +1,3730 @@
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
+ import collections.abc
19
+ from copy import deepcopy
20
+ from typing import (
21
+ TYPE_CHECKING,
22
+ Any,
23
+ ClassVar,
24
+ Dict,
25
+ Generic,
26
+ Iterable,
27
+ Literal,
28
+ Mapping,
29
+ MutableMapping,
30
+ Optional,
31
+ Sequence,
32
+ Union,
33
+ cast,
34
+ )
35
+
36
+ from elastic_transport.client_utils import DEFAULT
37
+
38
+ from .query import Query
39
+ from .response.aggs import AggResponse, BucketData, FieldBucketData, TopHitsData
40
+ from .utils import _R, AttrDict, DslBase
41
+
42
+ if TYPE_CHECKING:
43
+ from elastic_transport.client_utils import DefaultType
44
+
45
+ from . import types
46
+ from .document_base import InstrumentedField
47
+ from .search_base import SearchBase
48
+
49
+
50
+ def A(
51
+ name_or_agg: Union[MutableMapping[str, Any], "Agg[_R]", str],
52
+ filter: Optional[Union[str, "Query"]] = None,
53
+ **params: Any,
54
+ ) -> "Agg[_R]":
55
+ if filter is not None:
56
+ if name_or_agg != "filter":
57
+ raise ValueError(
58
+ "Aggregation %r doesn't accept positional argument 'filter'."
59
+ % name_or_agg
60
+ )
61
+ params["filter"] = filter
62
+
63
+ # {"terms": {"field": "tags"}, "aggs": {...}}
64
+ if isinstance(name_or_agg, collections.abc.MutableMapping):
65
+ if params:
66
+ raise ValueError("A() cannot accept parameters when passing in a dict.")
67
+ # copy to avoid modifying in-place
68
+ agg = deepcopy(name_or_agg)
69
+ # pop out nested aggs
70
+ aggs = agg.pop("aggs", None)
71
+ # pop out meta data
72
+ meta = agg.pop("meta", None)
73
+ # should be {"terms": {"field": "tags"}}
74
+ if len(agg) != 1:
75
+ raise ValueError(
76
+ 'A() can only accept dict with an aggregation ({"terms": {...}}). '
77
+ "Instead it got (%r)" % name_or_agg
78
+ )
79
+ agg_type, params = agg.popitem()
80
+ if aggs:
81
+ params = params.copy()
82
+ params["aggs"] = aggs
83
+ if meta:
84
+ params = params.copy()
85
+ params["meta"] = meta
86
+ return Agg[_R].get_dsl_class(agg_type)(_expand__to_dot=False, **params)
87
+
88
+ # Terms(...) just return the nested agg
89
+ elif isinstance(name_or_agg, Agg):
90
+ if params:
91
+ raise ValueError(
92
+ "A() cannot accept parameters when passing in an Agg object."
93
+ )
94
+ return name_or_agg
95
+
96
+ # "terms", field="tags"
97
+ return Agg[_R].get_dsl_class(name_or_agg)(**params)
98
+
99
+
100
+ class Agg(DslBase, Generic[_R]):
101
+ _type_name = "agg"
102
+ _type_shortcut = staticmethod(A)
103
+ name = ""
104
+
105
+ def __contains__(self, key: str) -> bool:
106
+ return False
107
+
108
+ def to_dict(self) -> Dict[str, Any]:
109
+ d = super().to_dict()
110
+ if isinstance(d[self.name], dict):
111
+ n = cast(Dict[str, Any], d[self.name])
112
+ if "meta" in n:
113
+ d["meta"] = n.pop("meta")
114
+ return d
115
+
116
+ def result(self, search: "SearchBase[_R]", data: Dict[str, Any]) -> AttrDict[Any]:
117
+ return AggResponse[_R](self, search, data)
118
+
119
+
120
+ class AggBase(Generic[_R]):
121
+ aggs: Dict[str, Agg[_R]]
122
+ _base: Agg[_R]
123
+ _params: Dict[str, Any]
124
+ _param_defs: ClassVar[Dict[str, Any]] = {
125
+ "aggs": {"type": "agg", "hash": True},
126
+ }
127
+
128
+ def __contains__(self, key: str) -> bool:
129
+ return key in self._params.get("aggs", {})
130
+
131
+ def __getitem__(self, agg_name: str) -> Agg[_R]:
132
+ agg = cast(
133
+ Agg[_R], self._params.setdefault("aggs", {})[agg_name]
134
+ ) # propagate KeyError
135
+
136
+ # make sure we're not mutating a shared state - whenever accessing a
137
+ # bucket, return a shallow copy of it to be safe
138
+ if isinstance(agg, Bucket):
139
+ agg = A(agg.name, **agg._params)
140
+ # be sure to store the copy so any modifications to it will affect us
141
+ self._params["aggs"][agg_name] = agg
142
+
143
+ return agg
144
+
145
+ def __setitem__(self, agg_name: str, agg: Agg[_R]) -> None:
146
+ self.aggs[agg_name] = A(agg)
147
+
148
+ def __iter__(self) -> Iterable[str]:
149
+ return iter(self.aggs)
150
+
151
+ def _agg(
152
+ self,
153
+ bucket: bool,
154
+ name: str,
155
+ agg_type: Union[Dict[str, Any], Agg[_R], str],
156
+ *args: Any,
157
+ **params: Any,
158
+ ) -> Agg[_R]:
159
+ agg = self[name] = A(agg_type, *args, **params)
160
+
161
+ # For chaining - when creating new buckets return them...
162
+ if bucket:
163
+ return agg
164
+ # otherwise return self._base so we can keep chaining
165
+ else:
166
+ return self._base
167
+
168
+ def metric(
169
+ self,
170
+ name: str,
171
+ agg_type: Union[Dict[str, Any], Agg[_R], str],
172
+ *args: Any,
173
+ **params: Any,
174
+ ) -> Agg[_R]:
175
+ return self._agg(False, name, agg_type, *args, **params)
176
+
177
+ def bucket(
178
+ self,
179
+ name: str,
180
+ agg_type: Union[Dict[str, Any], Agg[_R], str],
181
+ *args: Any,
182
+ **params: Any,
183
+ ) -> "Bucket[_R]":
184
+ return cast("Bucket[_R]", self._agg(True, name, agg_type, *args, **params))
185
+
186
+ def pipeline(
187
+ self,
188
+ name: str,
189
+ agg_type: Union[Dict[str, Any], Agg[_R], str],
190
+ *args: Any,
191
+ **params: Any,
192
+ ) -> "Pipeline[_R]":
193
+ return cast("Pipeline[_R]", self._agg(False, name, agg_type, *args, **params))
194
+
195
+ def result(self, search: "SearchBase[_R]", data: Any) -> AttrDict[Any]:
196
+ return BucketData(self, search, data) # type: ignore[arg-type]
197
+
198
+
199
+ class Bucket(AggBase[_R], Agg[_R]):
200
+ def __init__(self, **params: Any):
201
+ super().__init__(**params)
202
+ # remember self for chaining
203
+ self._base = self
204
+
205
+ def to_dict(self) -> Dict[str, Any]:
206
+ d = super(AggBase, self).to_dict()
207
+ if isinstance(d[self.name], dict):
208
+ n = cast(AttrDict[Any], d[self.name])
209
+ if "aggs" in n:
210
+ d["aggs"] = n.pop("aggs")
211
+ return d
212
+
213
+
214
+ class Pipeline(Agg[_R]):
215
+ pass
216
+
217
+
218
+ class AdjacencyMatrix(Bucket[_R]):
219
+ """
220
+ A bucket aggregation returning a form of adjacency matrix. The request
221
+ provides a collection of named filter expressions, similar to the
222
+ `filters` aggregation. Each bucket in the response represents a non-
223
+ empty cell in the matrix of intersecting filters.
224
+
225
+ :arg filters: Filters used to create buckets. At least one filter is
226
+ required.
227
+ :arg separator: Separator used to concatenate filter names. Defaults
228
+ to &.
229
+ """
230
+
231
+ name = "adjacency_matrix"
232
+ _param_defs = {
233
+ "filters": {"type": "query", "hash": True},
234
+ }
235
+
236
+ def __init__(
237
+ self,
238
+ *,
239
+ filters: Union[Mapping[str, Query], "DefaultType"] = DEFAULT,
240
+ separator: Union[str, "DefaultType"] = DEFAULT,
241
+ **kwargs: Any,
242
+ ):
243
+ super().__init__(filters=filters, separator=separator, **kwargs)
244
+
245
+
246
+ class AutoDateHistogram(Bucket[_R]):
247
+ """
248
+ A multi-bucket aggregation similar to the date histogram, except
249
+ instead of providing an interval to use as the width of each bucket, a
250
+ target number of buckets is provided.
251
+
252
+ :arg buckets: The target number of buckets. Defaults to `10` if
253
+ omitted.
254
+ :arg field: The field on which to run the aggregation.
255
+ :arg format: The date format used to format `key_as_string` in the
256
+ response. If no `format` is specified, the first date format
257
+ specified in the field mapping is used.
258
+ :arg minimum_interval: The minimum rounding interval. This can make
259
+ the collection process more efficient, as the aggregation will not
260
+ attempt to round at any interval lower than `minimum_interval`.
261
+ :arg missing: The value to apply to documents that do not have a
262
+ value. By default, documents without a value are ignored.
263
+ :arg offset: Time zone specified as a ISO 8601 UTC offset.
264
+ :arg params:
265
+ :arg script:
266
+ :arg time_zone: Time zone ID.
267
+ """
268
+
269
+ name = "auto_date_histogram"
270
+
271
+ def __init__(
272
+ self,
273
+ *,
274
+ buckets: Union[int, "DefaultType"] = DEFAULT,
275
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
276
+ format: Union[str, "DefaultType"] = DEFAULT,
277
+ minimum_interval: Union[
278
+ Literal["second", "minute", "hour", "day", "month", "year"], "DefaultType"
279
+ ] = DEFAULT,
280
+ missing: Any = DEFAULT,
281
+ offset: Union[str, "DefaultType"] = DEFAULT,
282
+ params: Union[Mapping[str, Any], "DefaultType"] = DEFAULT,
283
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
284
+ time_zone: Union[str, "DefaultType"] = DEFAULT,
285
+ **kwargs: Any,
286
+ ):
287
+ super().__init__(
288
+ buckets=buckets,
289
+ field=field,
290
+ format=format,
291
+ minimum_interval=minimum_interval,
292
+ missing=missing,
293
+ offset=offset,
294
+ params=params,
295
+ script=script,
296
+ time_zone=time_zone,
297
+ **kwargs,
298
+ )
299
+
300
+ def result(self, search: "SearchBase[_R]", data: Any) -> AttrDict[Any]:
301
+ return FieldBucketData(self, search, data)
302
+
303
+
304
+ class Avg(Agg[_R]):
305
+ """
306
+ A single-value metrics aggregation that computes the average of
307
+ numeric values that are extracted from the aggregated documents.
308
+
309
+ :arg format:
310
+ :arg field: The field on which to run the aggregation.
311
+ :arg missing: The value to apply to documents that do not have a
312
+ value. By default, documents without a value are ignored.
313
+ :arg script:
314
+ """
315
+
316
+ name = "avg"
317
+
318
+ def __init__(
319
+ self,
320
+ *,
321
+ format: Union[str, "DefaultType"] = DEFAULT,
322
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
323
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
324
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
325
+ **kwargs: Any,
326
+ ):
327
+ super().__init__(
328
+ format=format, field=field, missing=missing, script=script, **kwargs
329
+ )
330
+
331
+
332
+ class AvgBucket(Pipeline[_R]):
333
+ """
334
+ A sibling pipeline aggregation which calculates the mean value of a
335
+ specified metric in a sibling aggregation. The specified metric must
336
+ be numeric and the sibling aggregation must be a multi-bucket
337
+ aggregation.
338
+
339
+ :arg format: `DecimalFormat` pattern for the output value. If
340
+ specified, the formatted value is returned in the aggregation’s
341
+ `value_as_string` property.
342
+ :arg gap_policy: Policy to apply when gaps are found in the data.
343
+ Defaults to `skip` if omitted.
344
+ :arg buckets_path: Path to the buckets that contain one set of values
345
+ to correlate.
346
+ """
347
+
348
+ name = "avg_bucket"
349
+
350
+ def __init__(
351
+ self,
352
+ *,
353
+ format: Union[str, "DefaultType"] = DEFAULT,
354
+ gap_policy: Union[
355
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
356
+ ] = DEFAULT,
357
+ buckets_path: Union[
358
+ str, Sequence[str], Mapping[str, str], "DefaultType"
359
+ ] = DEFAULT,
360
+ **kwargs: Any,
361
+ ):
362
+ super().__init__(
363
+ format=format, gap_policy=gap_policy, buckets_path=buckets_path, **kwargs
364
+ )
365
+
366
+
367
+ class Boxplot(Agg[_R]):
368
+ """
369
+ A metrics aggregation that computes a box plot of numeric values
370
+ extracted from the aggregated documents.
371
+
372
+ :arg compression: Limits the maximum number of nodes used by the
373
+ underlying TDigest algorithm to `20 * compression`, enabling
374
+ control of memory usage and approximation error.
375
+ :arg field: The field on which to run the aggregation.
376
+ :arg missing: The value to apply to documents that do not have a
377
+ value. By default, documents without a value are ignored.
378
+ :arg script:
379
+ """
380
+
381
+ name = "boxplot"
382
+
383
+ def __init__(
384
+ self,
385
+ *,
386
+ compression: Union[float, "DefaultType"] = DEFAULT,
387
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
388
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
389
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
390
+ **kwargs: Any,
391
+ ):
392
+ super().__init__(
393
+ compression=compression,
394
+ field=field,
395
+ missing=missing,
396
+ script=script,
397
+ **kwargs,
398
+ )
399
+
400
+
401
+ class BucketScript(Pipeline[_R]):
402
+ """
403
+ A parent pipeline aggregation which runs a script which can perform
404
+ per bucket computations on metrics in the parent multi-bucket
405
+ aggregation.
406
+
407
+ :arg script: The script to run for this aggregation.
408
+ :arg format: `DecimalFormat` pattern for the output value. If
409
+ specified, the formatted value is returned in the aggregation’s
410
+ `value_as_string` property.
411
+ :arg gap_policy: Policy to apply when gaps are found in the data.
412
+ Defaults to `skip` if omitted.
413
+ :arg buckets_path: Path to the buckets that contain one set of values
414
+ to correlate.
415
+ """
416
+
417
+ name = "bucket_script"
418
+
419
+ def __init__(
420
+ self,
421
+ *,
422
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
423
+ format: Union[str, "DefaultType"] = DEFAULT,
424
+ gap_policy: Union[
425
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
426
+ ] = DEFAULT,
427
+ buckets_path: Union[
428
+ str, Sequence[str], Mapping[str, str], "DefaultType"
429
+ ] = DEFAULT,
430
+ **kwargs: Any,
431
+ ):
432
+ super().__init__(
433
+ script=script,
434
+ format=format,
435
+ gap_policy=gap_policy,
436
+ buckets_path=buckets_path,
437
+ **kwargs,
438
+ )
439
+
440
+
441
+ class BucketSelector(Pipeline[_R]):
442
+ """
443
+ A parent pipeline aggregation which runs a script to determine whether
444
+ the current bucket will be retained in the parent multi-bucket
445
+ aggregation.
446
+
447
+ :arg script: The script to run for this aggregation.
448
+ :arg format: `DecimalFormat` pattern for the output value. If
449
+ specified, the formatted value is returned in the aggregation’s
450
+ `value_as_string` property.
451
+ :arg gap_policy: Policy to apply when gaps are found in the data.
452
+ Defaults to `skip` if omitted.
453
+ :arg buckets_path: Path to the buckets that contain one set of values
454
+ to correlate.
455
+ """
456
+
457
+ name = "bucket_selector"
458
+
459
+ def __init__(
460
+ self,
461
+ *,
462
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
463
+ format: Union[str, "DefaultType"] = DEFAULT,
464
+ gap_policy: Union[
465
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
466
+ ] = DEFAULT,
467
+ buckets_path: Union[
468
+ str, Sequence[str], Mapping[str, str], "DefaultType"
469
+ ] = DEFAULT,
470
+ **kwargs: Any,
471
+ ):
472
+ super().__init__(
473
+ script=script,
474
+ format=format,
475
+ gap_policy=gap_policy,
476
+ buckets_path=buckets_path,
477
+ **kwargs,
478
+ )
479
+
480
+
481
+ class BucketSort(Bucket[_R]):
482
+ """
483
+ A parent pipeline aggregation which sorts the buckets of its parent
484
+ multi-bucket aggregation.
485
+
486
+ :arg from: Buckets in positions prior to `from` will be truncated.
487
+ :arg gap_policy: The policy to apply when gaps are found in the data.
488
+ Defaults to `skip` if omitted.
489
+ :arg size: The number of buckets to return. Defaults to all buckets of
490
+ the parent aggregation.
491
+ :arg sort: The list of fields to sort on.
492
+ """
493
+
494
+ name = "bucket_sort"
495
+
496
+ def __init__(
497
+ self,
498
+ *,
499
+ from_: Union[int, "DefaultType"] = DEFAULT,
500
+ gap_policy: Union[
501
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
502
+ ] = DEFAULT,
503
+ size: Union[int, "DefaultType"] = DEFAULT,
504
+ sort: Union[
505
+ Union[Union[str, "InstrumentedField"], "types.SortOptions"],
506
+ Sequence[Union[Union[str, "InstrumentedField"], "types.SortOptions"]],
507
+ Dict[str, Any],
508
+ "DefaultType",
509
+ ] = DEFAULT,
510
+ **kwargs: Any,
511
+ ):
512
+ super().__init__(
513
+ from_=from_, gap_policy=gap_policy, size=size, sort=sort, **kwargs
514
+ )
515
+
516
+
517
+ class BucketCountKsTest(Pipeline[_R]):
518
+ """
519
+ A sibling pipeline aggregation which runs a two sample
520
+ Kolmogorov–Smirnov test ("K-S test") against a provided distribution
521
+ and the distribution implied by the documents counts in the configured
522
+ sibling aggregation.
523
+
524
+ :arg alternative: A list of string values indicating which K-S test
525
+ alternative to calculate. The valid values are: "greater", "less",
526
+ "two_sided". This parameter is key for determining the K-S
527
+ statistic used when calculating the K-S test. Default value is all
528
+ possible alternative hypotheses.
529
+ :arg fractions: A list of doubles indicating the distribution of the
530
+ samples with which to compare to the `buckets_path` results. In
531
+ typical usage this is the overall proportion of documents in each
532
+ bucket, which is compared with the actual document proportions in
533
+ each bucket from the sibling aggregation counts. The default is to
534
+ assume that overall documents are uniformly distributed on these
535
+ buckets, which they would be if one used equal percentiles of a
536
+ metric to define the bucket end points.
537
+ :arg sampling_method: Indicates the sampling methodology when
538
+ calculating the K-S test. Note, this is sampling of the returned
539
+ values. This determines the cumulative distribution function (CDF)
540
+ points used comparing the two samples. Default is `upper_tail`,
541
+ which emphasizes the upper end of the CDF points. Valid options
542
+ are: `upper_tail`, `uniform`, and `lower_tail`.
543
+ :arg buckets_path: Path to the buckets that contain one set of values
544
+ to correlate.
545
+ """
546
+
547
+ name = "bucket_count_ks_test"
548
+
549
+ def __init__(
550
+ self,
551
+ *,
552
+ alternative: Union[Sequence[str], "DefaultType"] = DEFAULT,
553
+ fractions: Union[Sequence[float], "DefaultType"] = DEFAULT,
554
+ sampling_method: Union[str, "DefaultType"] = DEFAULT,
555
+ buckets_path: Union[
556
+ str, Sequence[str], Mapping[str, str], "DefaultType"
557
+ ] = DEFAULT,
558
+ **kwargs: Any,
559
+ ):
560
+ super().__init__(
561
+ alternative=alternative,
562
+ fractions=fractions,
563
+ sampling_method=sampling_method,
564
+ buckets_path=buckets_path,
565
+ **kwargs,
566
+ )
567
+
568
+
569
+ class BucketCorrelation(Pipeline[_R]):
570
+ """
571
+ A sibling pipeline aggregation which runs a correlation function on
572
+ the configured sibling multi-bucket aggregation.
573
+
574
+ :arg function: (required) The correlation function to execute.
575
+ :arg buckets_path: Path to the buckets that contain one set of values
576
+ to correlate.
577
+ """
578
+
579
+ name = "bucket_correlation"
580
+
581
+ def __init__(
582
+ self,
583
+ *,
584
+ function: Union[
585
+ "types.BucketCorrelationFunction", Dict[str, Any], "DefaultType"
586
+ ] = DEFAULT,
587
+ buckets_path: Union[
588
+ str, Sequence[str], Mapping[str, str], "DefaultType"
589
+ ] = DEFAULT,
590
+ **kwargs: Any,
591
+ ):
592
+ super().__init__(function=function, buckets_path=buckets_path, **kwargs)
593
+
594
+
595
+ class Cardinality(Agg[_R]):
596
+ """
597
+ A single-value metrics aggregation that calculates an approximate
598
+ count of distinct values.
599
+
600
+ :arg precision_threshold: A unique count below which counts are
601
+ expected to be close to accurate. This allows to trade memory for
602
+ accuracy. Defaults to `3000` if omitted.
603
+ :arg rehash:
604
+ :arg execution_hint: Mechanism by which cardinality aggregations is
605
+ run.
606
+ :arg field: The field on which to run the aggregation.
607
+ :arg missing: The value to apply to documents that do not have a
608
+ value. By default, documents without a value are ignored.
609
+ :arg script:
610
+ """
611
+
612
+ name = "cardinality"
613
+
614
+ def __init__(
615
+ self,
616
+ *,
617
+ precision_threshold: Union[int, "DefaultType"] = DEFAULT,
618
+ rehash: Union[bool, "DefaultType"] = DEFAULT,
619
+ execution_hint: Union[
620
+ Literal[
621
+ "global_ordinals",
622
+ "segment_ordinals",
623
+ "direct",
624
+ "save_memory_heuristic",
625
+ "save_time_heuristic",
626
+ ],
627
+ "DefaultType",
628
+ ] = DEFAULT,
629
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
630
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
631
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
632
+ **kwargs: Any,
633
+ ):
634
+ super().__init__(
635
+ precision_threshold=precision_threshold,
636
+ rehash=rehash,
637
+ execution_hint=execution_hint,
638
+ field=field,
639
+ missing=missing,
640
+ script=script,
641
+ **kwargs,
642
+ )
643
+
644
+
645
+ class CategorizeText(Bucket[_R]):
646
+ """
647
+ A multi-bucket aggregation that groups semi-structured text into
648
+ buckets.
649
+
650
+ :arg field: (required) The semi-structured text field to categorize.
651
+ :arg max_unique_tokens: The maximum number of unique tokens at any
652
+ position up to max_matched_tokens. Must be larger than 1. Smaller
653
+ values use less memory and create fewer categories. Larger values
654
+ will use more memory and create narrower categories. Max allowed
655
+ value is 100. Defaults to `50` if omitted.
656
+ :arg max_matched_tokens: The maximum number of token positions to
657
+ match on before attempting to merge categories. Larger values will
658
+ use more memory and create narrower categories. Max allowed value
659
+ is 100. Defaults to `5` if omitted.
660
+ :arg similarity_threshold: The minimum percentage of tokens that must
661
+ match for text to be added to the category bucket. Must be between
662
+ 1 and 100. The larger the value the narrower the categories.
663
+ Larger values will increase memory usage and create narrower
664
+ categories. Defaults to `50` if omitted.
665
+ :arg categorization_filters: This property expects an array of regular
666
+ expressions. The expressions are used to filter out matching
667
+ sequences from the categorization field values. You can use this
668
+ functionality to fine tune the categorization by excluding
669
+ sequences from consideration when categories are defined. For
670
+ example, you can exclude SQL statements that appear in your log
671
+ files. This property cannot be used at the same time as
672
+ categorization_analyzer. If you only want to define simple regular
673
+ expression filters that are applied prior to tokenization, setting
674
+ this property is the easiest method. If you also want to customize
675
+ the tokenizer or post-tokenization filtering, use the
676
+ categorization_analyzer property instead and include the filters
677
+ as pattern_replace character filters.
678
+ :arg categorization_analyzer: The categorization analyzer specifies
679
+ how the text is analyzed and tokenized before being categorized.
680
+ The syntax is very similar to that used to define the analyzer in
681
+ the [Analyze endpoint](https://www.elastic.co/guide/en/elasticsear
682
+ ch/reference/8.0/indices-analyze.html). This property cannot be
683
+ used at the same time as categorization_filters.
684
+ :arg shard_size: The number of categorization buckets to return from
685
+ each shard before merging all the results.
686
+ :arg size: The number of buckets to return. Defaults to `10` if
687
+ omitted.
688
+ :arg min_doc_count: The minimum number of documents in a bucket to be
689
+ returned to the results.
690
+ :arg shard_min_doc_count: The minimum number of documents in a bucket
691
+ to be returned from the shard before merging.
692
+ """
693
+
694
+ name = "categorize_text"
695
+
696
+ def __init__(
697
+ self,
698
+ *,
699
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
700
+ max_unique_tokens: Union[int, "DefaultType"] = DEFAULT,
701
+ max_matched_tokens: Union[int, "DefaultType"] = DEFAULT,
702
+ similarity_threshold: Union[int, "DefaultType"] = DEFAULT,
703
+ categorization_filters: Union[Sequence[str], "DefaultType"] = DEFAULT,
704
+ categorization_analyzer: Union[
705
+ str, "types.CustomCategorizeTextAnalyzer", Dict[str, Any], "DefaultType"
706
+ ] = DEFAULT,
707
+ shard_size: Union[int, "DefaultType"] = DEFAULT,
708
+ size: Union[int, "DefaultType"] = DEFAULT,
709
+ min_doc_count: Union[int, "DefaultType"] = DEFAULT,
710
+ shard_min_doc_count: Union[int, "DefaultType"] = DEFAULT,
711
+ **kwargs: Any,
712
+ ):
713
+ super().__init__(
714
+ field=field,
715
+ max_unique_tokens=max_unique_tokens,
716
+ max_matched_tokens=max_matched_tokens,
717
+ similarity_threshold=similarity_threshold,
718
+ categorization_filters=categorization_filters,
719
+ categorization_analyzer=categorization_analyzer,
720
+ shard_size=shard_size,
721
+ size=size,
722
+ min_doc_count=min_doc_count,
723
+ shard_min_doc_count=shard_min_doc_count,
724
+ **kwargs,
725
+ )
726
+
727
+
728
+ class Children(Bucket[_R]):
729
+ """
730
+ A single bucket aggregation that selects child documents that have the
731
+ specified type, as defined in a `join` field.
732
+
733
+ :arg type: The child type that should be selected.
734
+ """
735
+
736
+ name = "children"
737
+
738
+ def __init__(self, type: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any):
739
+ super().__init__(type=type, **kwargs)
740
+
741
+
742
+ class Composite(Bucket[_R]):
743
+ """
744
+ A multi-bucket aggregation that creates composite buckets from
745
+ different sources. Unlike the other multi-bucket aggregations, you can
746
+ use the `composite` aggregation to paginate *all* buckets from a
747
+ multi-level aggregation efficiently.
748
+
749
+ :arg after: When paginating, use the `after_key` value returned in the
750
+ previous response to retrieve the next page.
751
+ :arg size: The number of composite buckets that should be returned.
752
+ Defaults to `10` if omitted.
753
+ :arg sources: The value sources used to build composite buckets. Keys
754
+ are returned in the order of the `sources` definition.
755
+ """
756
+
757
+ name = "composite"
758
+
759
+ def __init__(
760
+ self,
761
+ *,
762
+ after: Union[
763
+ Mapping[
764
+ Union[str, "InstrumentedField"], Union[int, float, str, bool, None, Any]
765
+ ],
766
+ "DefaultType",
767
+ ] = DEFAULT,
768
+ size: Union[int, "DefaultType"] = DEFAULT,
769
+ sources: Union[Sequence[Mapping[str, Agg[_R]]], "DefaultType"] = DEFAULT,
770
+ **kwargs: Any,
771
+ ):
772
+ super().__init__(after=after, size=size, sources=sources, **kwargs)
773
+
774
+
775
+ class CumulativeCardinality(Pipeline[_R]):
776
+ """
777
+ A parent pipeline aggregation which calculates the cumulative
778
+ cardinality in a parent `histogram` or `date_histogram` aggregation.
779
+
780
+ :arg format: `DecimalFormat` pattern for the output value. If
781
+ specified, the formatted value is returned in the aggregation’s
782
+ `value_as_string` property.
783
+ :arg gap_policy: Policy to apply when gaps are found in the data.
784
+ Defaults to `skip` if omitted.
785
+ :arg buckets_path: Path to the buckets that contain one set of values
786
+ to correlate.
787
+ """
788
+
789
+ name = "cumulative_cardinality"
790
+
791
+ def __init__(
792
+ self,
793
+ *,
794
+ format: Union[str, "DefaultType"] = DEFAULT,
795
+ gap_policy: Union[
796
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
797
+ ] = DEFAULT,
798
+ buckets_path: Union[
799
+ str, Sequence[str], Mapping[str, str], "DefaultType"
800
+ ] = DEFAULT,
801
+ **kwargs: Any,
802
+ ):
803
+ super().__init__(
804
+ format=format, gap_policy=gap_policy, buckets_path=buckets_path, **kwargs
805
+ )
806
+
807
+
808
+ class CumulativeSum(Pipeline[_R]):
809
+ """
810
+ A parent pipeline aggregation which calculates the cumulative sum of a
811
+ specified metric in a parent `histogram` or `date_histogram`
812
+ aggregation.
813
+
814
+ :arg format: `DecimalFormat` pattern for the output value. If
815
+ specified, the formatted value is returned in the aggregation’s
816
+ `value_as_string` property.
817
+ :arg gap_policy: Policy to apply when gaps are found in the data.
818
+ Defaults to `skip` if omitted.
819
+ :arg buckets_path: Path to the buckets that contain one set of values
820
+ to correlate.
821
+ """
822
+
823
+ name = "cumulative_sum"
824
+
825
+ def __init__(
826
+ self,
827
+ *,
828
+ format: Union[str, "DefaultType"] = DEFAULT,
829
+ gap_policy: Union[
830
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
831
+ ] = DEFAULT,
832
+ buckets_path: Union[
833
+ str, Sequence[str], Mapping[str, str], "DefaultType"
834
+ ] = DEFAULT,
835
+ **kwargs: Any,
836
+ ):
837
+ super().__init__(
838
+ format=format, gap_policy=gap_policy, buckets_path=buckets_path, **kwargs
839
+ )
840
+
841
+
842
+ class DateHistogram(Bucket[_R]):
843
+ """
844
+ A multi-bucket values source based aggregation that can be applied on
845
+ date values or date range values extracted from the documents. It
846
+ dynamically builds fixed size (interval) buckets over the values.
847
+
848
+ :arg calendar_interval: Calendar-aware interval. Can be specified
849
+ using the unit name, such as `month`, or as a single unit
850
+ quantity, such as `1M`.
851
+ :arg extended_bounds: Enables extending the bounds of the histogram
852
+ beyond the data itself.
853
+ :arg hard_bounds: Limits the histogram to specified bounds.
854
+ :arg field: The date field whose values are use to build a histogram.
855
+ :arg fixed_interval: Fixed intervals: a fixed number of SI units and
856
+ never deviate, regardless of where they fall on the calendar.
857
+ :arg format: The date format used to format `key_as_string` in the
858
+ response. If no `format` is specified, the first date format
859
+ specified in the field mapping is used.
860
+ :arg interval:
861
+ :arg min_doc_count: Only returns buckets that have `min_doc_count`
862
+ number of documents. By default, all buckets between the first
863
+ bucket that matches documents and the last one are returned.
864
+ :arg missing: The value to apply to documents that do not have a
865
+ value. By default, documents without a value are ignored.
866
+ :arg offset: Changes the start value of each bucket by the specified
867
+ positive (`+`) or negative offset (`-`) duration.
868
+ :arg order: The sort order of the returned buckets.
869
+ :arg params:
870
+ :arg script:
871
+ :arg time_zone: Time zone used for bucketing and rounding. Defaults to
872
+ Coordinated Universal Time (UTC).
873
+ :arg keyed: Set to `true` to associate a unique string key with each
874
+ bucket and return the ranges as a hash rather than an array.
875
+ """
876
+
877
+ name = "date_histogram"
878
+
879
+ def __init__(
880
+ self,
881
+ *,
882
+ calendar_interval: Union[
883
+ Literal[
884
+ "second", "minute", "hour", "day", "week", "month", "quarter", "year"
885
+ ],
886
+ "DefaultType",
887
+ ] = DEFAULT,
888
+ extended_bounds: Union[
889
+ "types.ExtendedBounds", Dict[str, Any], "DefaultType"
890
+ ] = DEFAULT,
891
+ hard_bounds: Union[
892
+ "types.ExtendedBounds", Dict[str, Any], "DefaultType"
893
+ ] = DEFAULT,
894
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
895
+ fixed_interval: Any = DEFAULT,
896
+ format: Union[str, "DefaultType"] = DEFAULT,
897
+ interval: Any = DEFAULT,
898
+ min_doc_count: Union[int, "DefaultType"] = DEFAULT,
899
+ missing: Any = DEFAULT,
900
+ offset: Any = DEFAULT,
901
+ order: Union[
902
+ Mapping[Union[str, "InstrumentedField"], Literal["asc", "desc"]],
903
+ Sequence[Mapping[Union[str, "InstrumentedField"], Literal["asc", "desc"]]],
904
+ "DefaultType",
905
+ ] = DEFAULT,
906
+ params: Union[Mapping[str, Any], "DefaultType"] = DEFAULT,
907
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
908
+ time_zone: Union[str, "DefaultType"] = DEFAULT,
909
+ keyed: Union[bool, "DefaultType"] = DEFAULT,
910
+ **kwargs: Any,
911
+ ):
912
+ super().__init__(
913
+ calendar_interval=calendar_interval,
914
+ extended_bounds=extended_bounds,
915
+ hard_bounds=hard_bounds,
916
+ field=field,
917
+ fixed_interval=fixed_interval,
918
+ format=format,
919
+ interval=interval,
920
+ min_doc_count=min_doc_count,
921
+ missing=missing,
922
+ offset=offset,
923
+ order=order,
924
+ params=params,
925
+ script=script,
926
+ time_zone=time_zone,
927
+ keyed=keyed,
928
+ **kwargs,
929
+ )
930
+
931
+ def result(self, search: "SearchBase[_R]", data: Any) -> AttrDict[Any]:
932
+ return FieldBucketData(self, search, data)
933
+
934
+
935
+ class DateRange(Bucket[_R]):
936
+ """
937
+ A multi-bucket value source based aggregation that enables the user to
938
+ define a set of date ranges - each representing a bucket.
939
+
940
+ :arg field: The date field whose values are use to build ranges.
941
+ :arg format: The date format used to format `from` and `to` in the
942
+ response.
943
+ :arg missing: The value to apply to documents that do not have a
944
+ value. By default, documents without a value are ignored.
945
+ :arg ranges: Array of date ranges.
946
+ :arg time_zone: Time zone used to convert dates from another time zone
947
+ to UTC.
948
+ :arg keyed: Set to `true` to associate a unique string key with each
949
+ bucket and returns the ranges as a hash rather than an array.
950
+ """
951
+
952
+ name = "date_range"
953
+
954
+ def __init__(
955
+ self,
956
+ *,
957
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
958
+ format: Union[str, "DefaultType"] = DEFAULT,
959
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
960
+ ranges: Union[
961
+ Sequence["types.DateRangeExpression"],
962
+ Sequence[Dict[str, Any]],
963
+ "DefaultType",
964
+ ] = DEFAULT,
965
+ time_zone: Union[str, "DefaultType"] = DEFAULT,
966
+ keyed: Union[bool, "DefaultType"] = DEFAULT,
967
+ **kwargs: Any,
968
+ ):
969
+ super().__init__(
970
+ field=field,
971
+ format=format,
972
+ missing=missing,
973
+ ranges=ranges,
974
+ time_zone=time_zone,
975
+ keyed=keyed,
976
+ **kwargs,
977
+ )
978
+
979
+
980
+ class Derivative(Pipeline[_R]):
981
+ """
982
+ A parent pipeline aggregation which calculates the derivative of a
983
+ specified metric in a parent `histogram` or `date_histogram`
984
+ aggregation.
985
+
986
+ :arg format: `DecimalFormat` pattern for the output value. If
987
+ specified, the formatted value is returned in the aggregation’s
988
+ `value_as_string` property.
989
+ :arg gap_policy: Policy to apply when gaps are found in the data.
990
+ Defaults to `skip` if omitted.
991
+ :arg buckets_path: Path to the buckets that contain one set of values
992
+ to correlate.
993
+ """
994
+
995
+ name = "derivative"
996
+
997
+ def __init__(
998
+ self,
999
+ *,
1000
+ format: Union[str, "DefaultType"] = DEFAULT,
1001
+ gap_policy: Union[
1002
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
1003
+ ] = DEFAULT,
1004
+ buckets_path: Union[
1005
+ str, Sequence[str], Mapping[str, str], "DefaultType"
1006
+ ] = DEFAULT,
1007
+ **kwargs: Any,
1008
+ ):
1009
+ super().__init__(
1010
+ format=format, gap_policy=gap_policy, buckets_path=buckets_path, **kwargs
1011
+ )
1012
+
1013
+
1014
+ class DiversifiedSampler(Bucket[_R]):
1015
+ """
1016
+ A filtering aggregation used to limit any sub aggregations' processing
1017
+ to a sample of the top-scoring documents. Similar to the `sampler`
1018
+ aggregation, but adds the ability to limit the number of matches that
1019
+ share a common value.
1020
+
1021
+ :arg execution_hint: The type of value used for de-duplication.
1022
+ Defaults to `global_ordinals` if omitted.
1023
+ :arg max_docs_per_value: Limits how many documents are permitted per
1024
+ choice of de-duplicating value. Defaults to `1` if omitted.
1025
+ :arg script:
1026
+ :arg shard_size: Limits how many top-scoring documents are collected
1027
+ in the sample processed on each shard. Defaults to `100` if
1028
+ omitted.
1029
+ :arg field: The field used to provide values used for de-duplication.
1030
+ """
1031
+
1032
+ name = "diversified_sampler"
1033
+
1034
+ def __init__(
1035
+ self,
1036
+ *,
1037
+ execution_hint: Union[
1038
+ Literal["map", "global_ordinals", "bytes_hash"], "DefaultType"
1039
+ ] = DEFAULT,
1040
+ max_docs_per_value: Union[int, "DefaultType"] = DEFAULT,
1041
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
1042
+ shard_size: Union[int, "DefaultType"] = DEFAULT,
1043
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
1044
+ **kwargs: Any,
1045
+ ):
1046
+ super().__init__(
1047
+ execution_hint=execution_hint,
1048
+ max_docs_per_value=max_docs_per_value,
1049
+ script=script,
1050
+ shard_size=shard_size,
1051
+ field=field,
1052
+ **kwargs,
1053
+ )
1054
+
1055
+
1056
+ class ExtendedStats(Agg[_R]):
1057
+ """
1058
+ A multi-value metrics aggregation that computes stats over numeric
1059
+ values extracted from the aggregated documents.
1060
+
1061
+ :arg sigma: The number of standard deviations above/below the mean to
1062
+ display.
1063
+ :arg format:
1064
+ :arg field: The field on which to run the aggregation.
1065
+ :arg missing: The value to apply to documents that do not have a
1066
+ value. By default, documents without a value are ignored.
1067
+ :arg script:
1068
+ """
1069
+
1070
+ name = "extended_stats"
1071
+
1072
+ def __init__(
1073
+ self,
1074
+ *,
1075
+ sigma: Union[float, "DefaultType"] = DEFAULT,
1076
+ format: Union[str, "DefaultType"] = DEFAULT,
1077
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
1078
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
1079
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
1080
+ **kwargs: Any,
1081
+ ):
1082
+ super().__init__(
1083
+ sigma=sigma,
1084
+ format=format,
1085
+ field=field,
1086
+ missing=missing,
1087
+ script=script,
1088
+ **kwargs,
1089
+ )
1090
+
1091
+
1092
+ class ExtendedStatsBucket(Pipeline[_R]):
1093
+ """
1094
+ A sibling pipeline aggregation which calculates a variety of stats
1095
+ across all bucket of a specified metric in a sibling aggregation.
1096
+
1097
+ :arg sigma: The number of standard deviations above/below the mean to
1098
+ display.
1099
+ :arg format: `DecimalFormat` pattern for the output value. If
1100
+ specified, the formatted value is returned in the aggregation’s
1101
+ `value_as_string` property.
1102
+ :arg gap_policy: Policy to apply when gaps are found in the data.
1103
+ Defaults to `skip` if omitted.
1104
+ :arg buckets_path: Path to the buckets that contain one set of values
1105
+ to correlate.
1106
+ """
1107
+
1108
+ name = "extended_stats_bucket"
1109
+
1110
+ def __init__(
1111
+ self,
1112
+ *,
1113
+ sigma: Union[float, "DefaultType"] = DEFAULT,
1114
+ format: Union[str, "DefaultType"] = DEFAULT,
1115
+ gap_policy: Union[
1116
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
1117
+ ] = DEFAULT,
1118
+ buckets_path: Union[
1119
+ str, Sequence[str], Mapping[str, str], "DefaultType"
1120
+ ] = DEFAULT,
1121
+ **kwargs: Any,
1122
+ ):
1123
+ super().__init__(
1124
+ sigma=sigma,
1125
+ format=format,
1126
+ gap_policy=gap_policy,
1127
+ buckets_path=buckets_path,
1128
+ **kwargs,
1129
+ )
1130
+
1131
+
1132
+ class FrequentItemSets(Agg[_R]):
1133
+ """
1134
+ A bucket aggregation which finds frequent item sets, a form of
1135
+ association rules mining that identifies items that often occur
1136
+ together.
1137
+
1138
+ :arg fields: (required) Fields to analyze.
1139
+ :arg minimum_set_size: The minimum size of one item set. Defaults to
1140
+ `1` if omitted.
1141
+ :arg minimum_support: The minimum support of one item set. Defaults to
1142
+ `0.1` if omitted.
1143
+ :arg size: The number of top item sets to return. Defaults to `10` if
1144
+ omitted.
1145
+ :arg filter: Query that filters documents from analysis.
1146
+ """
1147
+
1148
+ name = "frequent_item_sets"
1149
+ _param_defs = {
1150
+ "filter": {"type": "query"},
1151
+ }
1152
+
1153
+ def __init__(
1154
+ self,
1155
+ *,
1156
+ fields: Union[
1157
+ Sequence["types.FrequentItemSetsField"],
1158
+ Sequence[Dict[str, Any]],
1159
+ "DefaultType",
1160
+ ] = DEFAULT,
1161
+ minimum_set_size: Union[int, "DefaultType"] = DEFAULT,
1162
+ minimum_support: Union[float, "DefaultType"] = DEFAULT,
1163
+ size: Union[int, "DefaultType"] = DEFAULT,
1164
+ filter: Union[Query, "DefaultType"] = DEFAULT,
1165
+ **kwargs: Any,
1166
+ ):
1167
+ super().__init__(
1168
+ fields=fields,
1169
+ minimum_set_size=minimum_set_size,
1170
+ minimum_support=minimum_support,
1171
+ size=size,
1172
+ filter=filter,
1173
+ **kwargs,
1174
+ )
1175
+
1176
+
1177
+ class Filter(Bucket[_R]):
1178
+ """
1179
+ A single bucket aggregation that narrows the set of documents to those
1180
+ that match a query.
1181
+
1182
+ :arg filter: A single bucket aggregation that narrows the set of
1183
+ documents to those that match a query.
1184
+ """
1185
+
1186
+ name = "filter"
1187
+ _param_defs = {
1188
+ "filter": {"type": "query"},
1189
+ "aggs": {"type": "agg", "hash": True},
1190
+ }
1191
+
1192
+ def __init__(self, filter: Union[Query, "DefaultType"] = DEFAULT, **kwargs: Any):
1193
+ super().__init__(filter=filter, **kwargs)
1194
+
1195
+ def to_dict(self) -> Dict[str, Any]:
1196
+ d = super().to_dict()
1197
+ if isinstance(d[self.name], dict):
1198
+ n = cast(AttrDict[Any], d[self.name])
1199
+ n.update(n.pop("filter", {}))
1200
+ return d
1201
+
1202
+
1203
+ class Filters(Bucket[_R]):
1204
+ """
1205
+ A multi-bucket aggregation where each bucket contains the documents
1206
+ that match a query.
1207
+
1208
+ :arg filters: Collection of queries from which to build buckets.
1209
+ :arg other_bucket: Set to `true` to add a bucket to the response which
1210
+ will contain all documents that do not match any of the given
1211
+ filters.
1212
+ :arg other_bucket_key: The key with which the other bucket is
1213
+ returned. Defaults to `_other_` if omitted.
1214
+ :arg keyed: By default, the named filters aggregation returns the
1215
+ buckets as an object. Set to `false` to return the buckets as an
1216
+ array of objects. Defaults to `True` if omitted.
1217
+ """
1218
+
1219
+ name = "filters"
1220
+ _param_defs = {
1221
+ "filters": {"type": "query", "hash": True},
1222
+ "aggs": {"type": "agg", "hash": True},
1223
+ }
1224
+
1225
+ def __init__(
1226
+ self,
1227
+ *,
1228
+ filters: Union[Dict[str, Query], "DefaultType"] = DEFAULT,
1229
+ other_bucket: Union[bool, "DefaultType"] = DEFAULT,
1230
+ other_bucket_key: Union[str, "DefaultType"] = DEFAULT,
1231
+ keyed: Union[bool, "DefaultType"] = DEFAULT,
1232
+ **kwargs: Any,
1233
+ ):
1234
+ super().__init__(
1235
+ filters=filters,
1236
+ other_bucket=other_bucket,
1237
+ other_bucket_key=other_bucket_key,
1238
+ keyed=keyed,
1239
+ **kwargs,
1240
+ )
1241
+
1242
+
1243
+ class GeoBounds(Agg[_R]):
1244
+ """
1245
+ A metric aggregation that computes the geographic bounding box
1246
+ containing all values for a Geopoint or Geoshape field.
1247
+
1248
+ :arg wrap_longitude: Specifies whether the bounding box should be
1249
+ allowed to overlap the international date line. Defaults to `True`
1250
+ if omitted.
1251
+ :arg field: The field on which to run the aggregation.
1252
+ :arg missing: The value to apply to documents that do not have a
1253
+ value. By default, documents without a value are ignored.
1254
+ :arg script:
1255
+ """
1256
+
1257
+ name = "geo_bounds"
1258
+
1259
+ def __init__(
1260
+ self,
1261
+ *,
1262
+ wrap_longitude: Union[bool, "DefaultType"] = DEFAULT,
1263
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
1264
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
1265
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
1266
+ **kwargs: Any,
1267
+ ):
1268
+ super().__init__(
1269
+ wrap_longitude=wrap_longitude,
1270
+ field=field,
1271
+ missing=missing,
1272
+ script=script,
1273
+ **kwargs,
1274
+ )
1275
+
1276
+
1277
+ class GeoCentroid(Agg[_R]):
1278
+ """
1279
+ A metric aggregation that computes the weighted centroid from all
1280
+ coordinate values for geo fields.
1281
+
1282
+ :arg count:
1283
+ :arg location:
1284
+ :arg field: The field on which to run the aggregation.
1285
+ :arg missing: The value to apply to documents that do not have a
1286
+ value. By default, documents without a value are ignored.
1287
+ :arg script:
1288
+ """
1289
+
1290
+ name = "geo_centroid"
1291
+
1292
+ def __init__(
1293
+ self,
1294
+ *,
1295
+ count: Union[int, "DefaultType"] = DEFAULT,
1296
+ location: Union[
1297
+ "types.LatLonGeoLocation",
1298
+ "types.GeoHashLocation",
1299
+ Sequence[float],
1300
+ str,
1301
+ Dict[str, Any],
1302
+ "DefaultType",
1303
+ ] = DEFAULT,
1304
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
1305
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
1306
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
1307
+ **kwargs: Any,
1308
+ ):
1309
+ super().__init__(
1310
+ count=count,
1311
+ location=location,
1312
+ field=field,
1313
+ missing=missing,
1314
+ script=script,
1315
+ **kwargs,
1316
+ )
1317
+
1318
+
1319
+ class GeoDistance(Bucket[_R]):
1320
+ """
1321
+ A multi-bucket aggregation that works on `geo_point` fields. Evaluates
1322
+ the distance of each document value from an origin point and
1323
+ determines the buckets it belongs to, based on ranges defined in the
1324
+ request.
1325
+
1326
+ :arg distance_type: The distance calculation type. Defaults to `arc`
1327
+ if omitted.
1328
+ :arg field: A field of type `geo_point` used to evaluate the distance.
1329
+ :arg origin: The origin used to evaluate the distance.
1330
+ :arg ranges: An array of ranges used to bucket documents.
1331
+ :arg unit: The distance unit. Defaults to `m` if omitted.
1332
+ """
1333
+
1334
+ name = "geo_distance"
1335
+
1336
+ def __init__(
1337
+ self,
1338
+ *,
1339
+ distance_type: Union[Literal["arc", "plane"], "DefaultType"] = DEFAULT,
1340
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
1341
+ origin: Union[
1342
+ "types.LatLonGeoLocation",
1343
+ "types.GeoHashLocation",
1344
+ Sequence[float],
1345
+ str,
1346
+ Dict[str, Any],
1347
+ "DefaultType",
1348
+ ] = DEFAULT,
1349
+ ranges: Union[
1350
+ Sequence["types.AggregationRange"], Sequence[Dict[str, Any]], "DefaultType"
1351
+ ] = DEFAULT,
1352
+ unit: Union[
1353
+ Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "DefaultType"
1354
+ ] = DEFAULT,
1355
+ **kwargs: Any,
1356
+ ):
1357
+ super().__init__(
1358
+ distance_type=distance_type,
1359
+ field=field,
1360
+ origin=origin,
1361
+ ranges=ranges,
1362
+ unit=unit,
1363
+ **kwargs,
1364
+ )
1365
+
1366
+
1367
+ class GeohashGrid(Bucket[_R]):
1368
+ """
1369
+ A multi-bucket aggregation that groups `geo_point` and `geo_shape`
1370
+ values into buckets that represent a grid. Each cell is labeled using
1371
+ a geohash which is of user-definable precision.
1372
+
1373
+ :arg bounds: The bounding box to filter the points in each bucket.
1374
+ :arg field: Field containing indexed `geo_point` or `geo_shape`
1375
+ values. If the field contains an array, `geohash_grid` aggregates
1376
+ all array values.
1377
+ :arg precision: The string length of the geohashes used to define
1378
+ cells/buckets in the results. Defaults to `5` if omitted.
1379
+ :arg shard_size: Allows for more accurate counting of the top cells
1380
+ returned in the final result the aggregation. Defaults to
1381
+ returning `max(10,(size x number-of-shards))` buckets from each
1382
+ shard.
1383
+ :arg size: The maximum number of geohash buckets to return. Defaults
1384
+ to `10000` if omitted.
1385
+ """
1386
+
1387
+ name = "geohash_grid"
1388
+
1389
+ def __init__(
1390
+ self,
1391
+ *,
1392
+ bounds: Union[
1393
+ "types.CoordsGeoBounds",
1394
+ "types.TopLeftBottomRightGeoBounds",
1395
+ "types.TopRightBottomLeftGeoBounds",
1396
+ "types.WktGeoBounds",
1397
+ Dict[str, Any],
1398
+ "DefaultType",
1399
+ ] = DEFAULT,
1400
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
1401
+ precision: Union[float, str, "DefaultType"] = DEFAULT,
1402
+ shard_size: Union[int, "DefaultType"] = DEFAULT,
1403
+ size: Union[int, "DefaultType"] = DEFAULT,
1404
+ **kwargs: Any,
1405
+ ):
1406
+ super().__init__(
1407
+ bounds=bounds,
1408
+ field=field,
1409
+ precision=precision,
1410
+ shard_size=shard_size,
1411
+ size=size,
1412
+ **kwargs,
1413
+ )
1414
+
1415
+
1416
+ class GeoLine(Agg[_R]):
1417
+ """
1418
+ Aggregates all `geo_point` values within a bucket into a `LineString`
1419
+ ordered by the chosen sort field.
1420
+
1421
+ :arg point: (required) The name of the geo_point field.
1422
+ :arg sort: (required) The name of the numeric field to use as the sort
1423
+ key for ordering the points. When the `geo_line` aggregation is
1424
+ nested inside a `time_series` aggregation, this field defaults to
1425
+ `@timestamp`, and any other value will result in error.
1426
+ :arg include_sort: When `true`, returns an additional array of the
1427
+ sort values in the feature properties.
1428
+ :arg sort_order: The order in which the line is sorted (ascending or
1429
+ descending). Defaults to `asc` if omitted.
1430
+ :arg size: The maximum length of the line represented in the
1431
+ aggregation. Valid sizes are between 1 and 10000. Defaults to
1432
+ `10000` if omitted.
1433
+ """
1434
+
1435
+ name = "geo_line"
1436
+
1437
+ def __init__(
1438
+ self,
1439
+ *,
1440
+ point: Union["types.GeoLinePoint", Dict[str, Any], "DefaultType"] = DEFAULT,
1441
+ sort: Union["types.GeoLineSort", Dict[str, Any], "DefaultType"] = DEFAULT,
1442
+ include_sort: Union[bool, "DefaultType"] = DEFAULT,
1443
+ sort_order: Union[Literal["asc", "desc"], "DefaultType"] = DEFAULT,
1444
+ size: Union[int, "DefaultType"] = DEFAULT,
1445
+ **kwargs: Any,
1446
+ ):
1447
+ super().__init__(
1448
+ point=point,
1449
+ sort=sort,
1450
+ include_sort=include_sort,
1451
+ sort_order=sort_order,
1452
+ size=size,
1453
+ **kwargs,
1454
+ )
1455
+
1456
+
1457
+ class GeotileGrid(Bucket[_R]):
1458
+ """
1459
+ A multi-bucket aggregation that groups `geo_point` and `geo_shape`
1460
+ values into buckets that represent a grid. Each cell corresponds to a
1461
+ map tile as used by many online map sites.
1462
+
1463
+ :arg field: Field containing indexed `geo_point` or `geo_shape`
1464
+ values. If the field contains an array, `geotile_grid` aggregates
1465
+ all array values.
1466
+ :arg precision: Integer zoom of the key used to define cells/buckets
1467
+ in the results. Values outside of the range [0,29] will be
1468
+ rejected. Defaults to `7` if omitted.
1469
+ :arg shard_size: Allows for more accurate counting of the top cells
1470
+ returned in the final result the aggregation. Defaults to
1471
+ returning `max(10,(size x number-of-shards))` buckets from each
1472
+ shard.
1473
+ :arg size: The maximum number of buckets to return. Defaults to
1474
+ `10000` if omitted.
1475
+ :arg bounds: A bounding box to filter the geo-points or geo-shapes in
1476
+ each bucket.
1477
+ """
1478
+
1479
+ name = "geotile_grid"
1480
+
1481
+ def __init__(
1482
+ self,
1483
+ *,
1484
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
1485
+ precision: Union[float, "DefaultType"] = DEFAULT,
1486
+ shard_size: Union[int, "DefaultType"] = DEFAULT,
1487
+ size: Union[int, "DefaultType"] = DEFAULT,
1488
+ bounds: Union[
1489
+ "types.CoordsGeoBounds",
1490
+ "types.TopLeftBottomRightGeoBounds",
1491
+ "types.TopRightBottomLeftGeoBounds",
1492
+ "types.WktGeoBounds",
1493
+ Dict[str, Any],
1494
+ "DefaultType",
1495
+ ] = DEFAULT,
1496
+ **kwargs: Any,
1497
+ ):
1498
+ super().__init__(
1499
+ field=field,
1500
+ precision=precision,
1501
+ shard_size=shard_size,
1502
+ size=size,
1503
+ bounds=bounds,
1504
+ **kwargs,
1505
+ )
1506
+
1507
+
1508
+ class GeohexGrid(Bucket[_R]):
1509
+ """
1510
+ A multi-bucket aggregation that groups `geo_point` and `geo_shape`
1511
+ values into buckets that represent a grid. Each cell corresponds to a
1512
+ H3 cell index and is labeled using the H3Index representation.
1513
+
1514
+ :arg field: (required) Field containing indexed `geo_point` or
1515
+ `geo_shape` values. If the field contains an array, `geohex_grid`
1516
+ aggregates all array values.
1517
+ :arg precision: Integer zoom of the key used to defined cells or
1518
+ buckets in the results. Value should be between 0-15. Defaults to
1519
+ `6` if omitted.
1520
+ :arg bounds: Bounding box used to filter the geo-points in each
1521
+ bucket.
1522
+ :arg size: Maximum number of buckets to return. Defaults to `10000` if
1523
+ omitted.
1524
+ :arg shard_size: Number of buckets returned from each shard.
1525
+ """
1526
+
1527
+ name = "geohex_grid"
1528
+
1529
+ def __init__(
1530
+ self,
1531
+ *,
1532
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
1533
+ precision: Union[int, "DefaultType"] = DEFAULT,
1534
+ bounds: Union[
1535
+ "types.CoordsGeoBounds",
1536
+ "types.TopLeftBottomRightGeoBounds",
1537
+ "types.TopRightBottomLeftGeoBounds",
1538
+ "types.WktGeoBounds",
1539
+ Dict[str, Any],
1540
+ "DefaultType",
1541
+ ] = DEFAULT,
1542
+ size: Union[int, "DefaultType"] = DEFAULT,
1543
+ shard_size: Union[int, "DefaultType"] = DEFAULT,
1544
+ **kwargs: Any,
1545
+ ):
1546
+ super().__init__(
1547
+ field=field,
1548
+ precision=precision,
1549
+ bounds=bounds,
1550
+ size=size,
1551
+ shard_size=shard_size,
1552
+ **kwargs,
1553
+ )
1554
+
1555
+
1556
+ class Global(Bucket[_R]):
1557
+ """
1558
+ Defines a single bucket of all the documents within the search
1559
+ execution context. This context is defined by the indices and the
1560
+ document types you’re searching on, but is not influenced by the
1561
+ search query itself.
1562
+ """
1563
+
1564
+ name = "global"
1565
+
1566
+ def __init__(self, **kwargs: Any):
1567
+ super().__init__(**kwargs)
1568
+
1569
+
1570
+ class Histogram(Bucket[_R]):
1571
+ """
1572
+ A multi-bucket values source based aggregation that can be applied on
1573
+ numeric values or numeric range values extracted from the documents.
1574
+ It dynamically builds fixed size (interval) buckets over the values.
1575
+
1576
+ :arg extended_bounds: Enables extending the bounds of the histogram
1577
+ beyond the data itself.
1578
+ :arg hard_bounds: Limits the range of buckets in the histogram. It is
1579
+ particularly useful in the case of open data ranges that can
1580
+ result in a very large number of buckets.
1581
+ :arg field: The name of the field to aggregate on.
1582
+ :arg interval: The interval for the buckets. Must be a positive
1583
+ decimal.
1584
+ :arg min_doc_count: Only returns buckets that have `min_doc_count`
1585
+ number of documents. By default, the response will fill gaps in
1586
+ the histogram with empty buckets.
1587
+ :arg missing: The value to apply to documents that do not have a
1588
+ value. By default, documents without a value are ignored.
1589
+ :arg offset: By default, the bucket keys start with 0 and then
1590
+ continue in even spaced steps of `interval`. The bucket boundaries
1591
+ can be shifted by using the `offset` option.
1592
+ :arg order: The sort order of the returned buckets. By default, the
1593
+ returned buckets are sorted by their key ascending.
1594
+ :arg script:
1595
+ :arg format:
1596
+ :arg keyed: If `true`, returns buckets as a hash instead of an array,
1597
+ keyed by the bucket keys.
1598
+ """
1599
+
1600
+ name = "histogram"
1601
+
1602
+ def __init__(
1603
+ self,
1604
+ *,
1605
+ extended_bounds: Union[
1606
+ "types.ExtendedBounds", Dict[str, Any], "DefaultType"
1607
+ ] = DEFAULT,
1608
+ hard_bounds: Union[
1609
+ "types.ExtendedBounds", Dict[str, Any], "DefaultType"
1610
+ ] = DEFAULT,
1611
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
1612
+ interval: Union[float, "DefaultType"] = DEFAULT,
1613
+ min_doc_count: Union[int, "DefaultType"] = DEFAULT,
1614
+ missing: Union[float, "DefaultType"] = DEFAULT,
1615
+ offset: Union[float, "DefaultType"] = DEFAULT,
1616
+ order: Union[
1617
+ Mapping[Union[str, "InstrumentedField"], Literal["asc", "desc"]],
1618
+ Sequence[Mapping[Union[str, "InstrumentedField"], Literal["asc", "desc"]]],
1619
+ "DefaultType",
1620
+ ] = DEFAULT,
1621
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
1622
+ format: Union[str, "DefaultType"] = DEFAULT,
1623
+ keyed: Union[bool, "DefaultType"] = DEFAULT,
1624
+ **kwargs: Any,
1625
+ ):
1626
+ super().__init__(
1627
+ extended_bounds=extended_bounds,
1628
+ hard_bounds=hard_bounds,
1629
+ field=field,
1630
+ interval=interval,
1631
+ min_doc_count=min_doc_count,
1632
+ missing=missing,
1633
+ offset=offset,
1634
+ order=order,
1635
+ script=script,
1636
+ format=format,
1637
+ keyed=keyed,
1638
+ **kwargs,
1639
+ )
1640
+
1641
+ def result(self, search: "SearchBase[_R]", data: Any) -> AttrDict[Any]:
1642
+ return FieldBucketData(self, search, data)
1643
+
1644
+
1645
+ class IPRange(Bucket[_R]):
1646
+ """
1647
+ A multi-bucket value source based aggregation that enables the user to
1648
+ define a set of IP ranges - each representing a bucket.
1649
+
1650
+ :arg field: The date field whose values are used to build ranges.
1651
+ :arg ranges: Array of IP ranges.
1652
+ """
1653
+
1654
+ name = "ip_range"
1655
+
1656
+ def __init__(
1657
+ self,
1658
+ *,
1659
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
1660
+ ranges: Union[
1661
+ Sequence["types.IpRangeAggregationRange"],
1662
+ Sequence[Dict[str, Any]],
1663
+ "DefaultType",
1664
+ ] = DEFAULT,
1665
+ **kwargs: Any,
1666
+ ):
1667
+ super().__init__(field=field, ranges=ranges, **kwargs)
1668
+
1669
+
1670
+ class IPPrefix(Bucket[_R]):
1671
+ """
1672
+ A bucket aggregation that groups documents based on the network or
1673
+ sub-network of an IP address.
1674
+
1675
+ :arg field: (required) The IP address field to aggregation on. The
1676
+ field mapping type must be `ip`.
1677
+ :arg prefix_length: (required) Length of the network prefix. For IPv4
1678
+ addresses the accepted range is [0, 32]. For IPv6 addresses the
1679
+ accepted range is [0, 128].
1680
+ :arg is_ipv6: Defines whether the prefix applies to IPv6 addresses.
1681
+ :arg append_prefix_length: Defines whether the prefix length is
1682
+ appended to IP address keys in the response.
1683
+ :arg keyed: Defines whether buckets are returned as a hash rather than
1684
+ an array in the response.
1685
+ :arg min_doc_count: Minimum number of documents in a bucket for it to
1686
+ be included in the response. Defaults to `1` if omitted.
1687
+ """
1688
+
1689
+ name = "ip_prefix"
1690
+
1691
+ def __init__(
1692
+ self,
1693
+ *,
1694
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
1695
+ prefix_length: Union[int, "DefaultType"] = DEFAULT,
1696
+ is_ipv6: Union[bool, "DefaultType"] = DEFAULT,
1697
+ append_prefix_length: Union[bool, "DefaultType"] = DEFAULT,
1698
+ keyed: Union[bool, "DefaultType"] = DEFAULT,
1699
+ min_doc_count: Union[int, "DefaultType"] = DEFAULT,
1700
+ **kwargs: Any,
1701
+ ):
1702
+ super().__init__(
1703
+ field=field,
1704
+ prefix_length=prefix_length,
1705
+ is_ipv6=is_ipv6,
1706
+ append_prefix_length=append_prefix_length,
1707
+ keyed=keyed,
1708
+ min_doc_count=min_doc_count,
1709
+ **kwargs,
1710
+ )
1711
+
1712
+
1713
+ class Inference(Pipeline[_R]):
1714
+ """
1715
+ A parent pipeline aggregation which loads a pre-trained model and
1716
+ performs inference on the collated result fields from the parent
1717
+ bucket aggregation.
1718
+
1719
+ :arg model_id: (required) The ID or alias for the trained model.
1720
+ :arg inference_config: Contains the inference type and its options.
1721
+ :arg format: `DecimalFormat` pattern for the output value. If
1722
+ specified, the formatted value is returned in the aggregation’s
1723
+ `value_as_string` property.
1724
+ :arg gap_policy: Policy to apply when gaps are found in the data.
1725
+ Defaults to `skip` if omitted.
1726
+ :arg buckets_path: Path to the buckets that contain one set of values
1727
+ to correlate.
1728
+ """
1729
+
1730
+ name = "inference"
1731
+
1732
+ def __init__(
1733
+ self,
1734
+ *,
1735
+ model_id: Union[str, "DefaultType"] = DEFAULT,
1736
+ inference_config: Union[
1737
+ "types.InferenceConfigContainer", Dict[str, Any], "DefaultType"
1738
+ ] = DEFAULT,
1739
+ format: Union[str, "DefaultType"] = DEFAULT,
1740
+ gap_policy: Union[
1741
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
1742
+ ] = DEFAULT,
1743
+ buckets_path: Union[
1744
+ str, Sequence[str], Mapping[str, str], "DefaultType"
1745
+ ] = DEFAULT,
1746
+ **kwargs: Any,
1747
+ ):
1748
+ super().__init__(
1749
+ model_id=model_id,
1750
+ inference_config=inference_config,
1751
+ format=format,
1752
+ gap_policy=gap_policy,
1753
+ buckets_path=buckets_path,
1754
+ **kwargs,
1755
+ )
1756
+
1757
+
1758
+ class Line(Agg[_R]):
1759
+ """
1760
+ :arg point: (required) The name of the geo_point field.
1761
+ :arg sort: (required) The name of the numeric field to use as the sort
1762
+ key for ordering the points. When the `geo_line` aggregation is
1763
+ nested inside a `time_series` aggregation, this field defaults to
1764
+ `@timestamp`, and any other value will result in error.
1765
+ :arg include_sort: When `true`, returns an additional array of the
1766
+ sort values in the feature properties.
1767
+ :arg sort_order: The order in which the line is sorted (ascending or
1768
+ descending). Defaults to `asc` if omitted.
1769
+ :arg size: The maximum length of the line represented in the
1770
+ aggregation. Valid sizes are between 1 and 10000. Defaults to
1771
+ `10000` if omitted.
1772
+ """
1773
+
1774
+ name = "line"
1775
+
1776
+ def __init__(
1777
+ self,
1778
+ *,
1779
+ point: Union["types.GeoLinePoint", Dict[str, Any], "DefaultType"] = DEFAULT,
1780
+ sort: Union["types.GeoLineSort", Dict[str, Any], "DefaultType"] = DEFAULT,
1781
+ include_sort: Union[bool, "DefaultType"] = DEFAULT,
1782
+ sort_order: Union[Literal["asc", "desc"], "DefaultType"] = DEFAULT,
1783
+ size: Union[int, "DefaultType"] = DEFAULT,
1784
+ **kwargs: Any,
1785
+ ):
1786
+ super().__init__(
1787
+ point=point,
1788
+ sort=sort,
1789
+ include_sort=include_sort,
1790
+ sort_order=sort_order,
1791
+ size=size,
1792
+ **kwargs,
1793
+ )
1794
+
1795
+
1796
+ class MatrixStats(Agg[_R]):
1797
+ """
1798
+ A numeric aggregation that computes the following statistics over a
1799
+ set of document fields: `count`, `mean`, `variance`, `skewness`,
1800
+ `kurtosis`, `covariance`, and `covariance`.
1801
+
1802
+ :arg mode: Array value the aggregation will use for array or multi-
1803
+ valued fields. Defaults to `avg` if omitted.
1804
+ :arg fields: An array of fields for computing the statistics.
1805
+ :arg missing: The value to apply to documents that do not have a
1806
+ value. By default, documents without a value are ignored.
1807
+ """
1808
+
1809
+ name = "matrix_stats"
1810
+
1811
+ def __init__(
1812
+ self,
1813
+ *,
1814
+ mode: Union[
1815
+ Literal["min", "max", "sum", "avg", "median"], "DefaultType"
1816
+ ] = DEFAULT,
1817
+ fields: Union[
1818
+ Union[str, "InstrumentedField"],
1819
+ Sequence[Union[str, "InstrumentedField"]],
1820
+ "DefaultType",
1821
+ ] = DEFAULT,
1822
+ missing: Union[
1823
+ Mapping[Union[str, "InstrumentedField"], float], "DefaultType"
1824
+ ] = DEFAULT,
1825
+ **kwargs: Any,
1826
+ ):
1827
+ super().__init__(mode=mode, fields=fields, missing=missing, **kwargs)
1828
+
1829
+
1830
+ class Max(Agg[_R]):
1831
+ """
1832
+ A single-value metrics aggregation that returns the maximum value
1833
+ among the numeric values extracted from the aggregated documents.
1834
+
1835
+ :arg format:
1836
+ :arg field: The field on which to run the aggregation.
1837
+ :arg missing: The value to apply to documents that do not have a
1838
+ value. By default, documents without a value are ignored.
1839
+ :arg script:
1840
+ """
1841
+
1842
+ name = "max"
1843
+
1844
+ def __init__(
1845
+ self,
1846
+ *,
1847
+ format: Union[str, "DefaultType"] = DEFAULT,
1848
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
1849
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
1850
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
1851
+ **kwargs: Any,
1852
+ ):
1853
+ super().__init__(
1854
+ format=format, field=field, missing=missing, script=script, **kwargs
1855
+ )
1856
+
1857
+
1858
+ class MaxBucket(Pipeline[_R]):
1859
+ """
1860
+ A sibling pipeline aggregation which identifies the bucket(s) with the
1861
+ maximum value of a specified metric in a sibling aggregation and
1862
+ outputs both the value and the key(s) of the bucket(s).
1863
+
1864
+ :arg format: `DecimalFormat` pattern for the output value. If
1865
+ specified, the formatted value is returned in the aggregation’s
1866
+ `value_as_string` property.
1867
+ :arg gap_policy: Policy to apply when gaps are found in the data.
1868
+ Defaults to `skip` if omitted.
1869
+ :arg buckets_path: Path to the buckets that contain one set of values
1870
+ to correlate.
1871
+ """
1872
+
1873
+ name = "max_bucket"
1874
+
1875
+ def __init__(
1876
+ self,
1877
+ *,
1878
+ format: Union[str, "DefaultType"] = DEFAULT,
1879
+ gap_policy: Union[
1880
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
1881
+ ] = DEFAULT,
1882
+ buckets_path: Union[
1883
+ str, Sequence[str], Mapping[str, str], "DefaultType"
1884
+ ] = DEFAULT,
1885
+ **kwargs: Any,
1886
+ ):
1887
+ super().__init__(
1888
+ format=format, gap_policy=gap_policy, buckets_path=buckets_path, **kwargs
1889
+ )
1890
+
1891
+
1892
+ class MedianAbsoluteDeviation(Agg[_R]):
1893
+ """
1894
+ A single-value aggregation that approximates the median absolute
1895
+ deviation of its search results.
1896
+
1897
+ :arg compression: Limits the maximum number of nodes used by the
1898
+ underlying TDigest algorithm to `20 * compression`, enabling
1899
+ control of memory usage and approximation error. Defaults to
1900
+ `1000` if omitted.
1901
+ :arg format:
1902
+ :arg field: The field on which to run the aggregation.
1903
+ :arg missing: The value to apply to documents that do not have a
1904
+ value. By default, documents without a value are ignored.
1905
+ :arg script:
1906
+ """
1907
+
1908
+ name = "median_absolute_deviation"
1909
+
1910
+ def __init__(
1911
+ self,
1912
+ *,
1913
+ compression: Union[float, "DefaultType"] = DEFAULT,
1914
+ format: Union[str, "DefaultType"] = DEFAULT,
1915
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
1916
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
1917
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
1918
+ **kwargs: Any,
1919
+ ):
1920
+ super().__init__(
1921
+ compression=compression,
1922
+ format=format,
1923
+ field=field,
1924
+ missing=missing,
1925
+ script=script,
1926
+ **kwargs,
1927
+ )
1928
+
1929
+
1930
+ class Min(Agg[_R]):
1931
+ """
1932
+ A single-value metrics aggregation that returns the minimum value
1933
+ among numeric values extracted from the aggregated documents.
1934
+
1935
+ :arg format:
1936
+ :arg field: The field on which to run the aggregation.
1937
+ :arg missing: The value to apply to documents that do not have a
1938
+ value. By default, documents without a value are ignored.
1939
+ :arg script:
1940
+ """
1941
+
1942
+ name = "min"
1943
+
1944
+ def __init__(
1945
+ self,
1946
+ *,
1947
+ format: Union[str, "DefaultType"] = DEFAULT,
1948
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
1949
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
1950
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
1951
+ **kwargs: Any,
1952
+ ):
1953
+ super().__init__(
1954
+ format=format, field=field, missing=missing, script=script, **kwargs
1955
+ )
1956
+
1957
+
1958
+ class MinBucket(Pipeline[_R]):
1959
+ """
1960
+ A sibling pipeline aggregation which identifies the bucket(s) with the
1961
+ minimum value of a specified metric in a sibling aggregation and
1962
+ outputs both the value and the key(s) of the bucket(s).
1963
+
1964
+ :arg format: `DecimalFormat` pattern for the output value. If
1965
+ specified, the formatted value is returned in the aggregation’s
1966
+ `value_as_string` property.
1967
+ :arg gap_policy: Policy to apply when gaps are found in the data.
1968
+ Defaults to `skip` if omitted.
1969
+ :arg buckets_path: Path to the buckets that contain one set of values
1970
+ to correlate.
1971
+ """
1972
+
1973
+ name = "min_bucket"
1974
+
1975
+ def __init__(
1976
+ self,
1977
+ *,
1978
+ format: Union[str, "DefaultType"] = DEFAULT,
1979
+ gap_policy: Union[
1980
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
1981
+ ] = DEFAULT,
1982
+ buckets_path: Union[
1983
+ str, Sequence[str], Mapping[str, str], "DefaultType"
1984
+ ] = DEFAULT,
1985
+ **kwargs: Any,
1986
+ ):
1987
+ super().__init__(
1988
+ format=format, gap_policy=gap_policy, buckets_path=buckets_path, **kwargs
1989
+ )
1990
+
1991
+
1992
+ class Missing(Bucket[_R]):
1993
+ """
1994
+ A field data based single bucket aggregation, that creates a bucket of
1995
+ all documents in the current document set context that are missing a
1996
+ field value (effectively, missing a field or having the configured
1997
+ NULL value set).
1998
+
1999
+ :arg field: The name of the field.
2000
+ :arg missing:
2001
+ """
2002
+
2003
+ name = "missing"
2004
+
2005
+ def __init__(
2006
+ self,
2007
+ *,
2008
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
2009
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
2010
+ **kwargs: Any,
2011
+ ):
2012
+ super().__init__(field=field, missing=missing, **kwargs)
2013
+
2014
+
2015
+ class MovingAvg(Pipeline[_R]):
2016
+ """ """
2017
+
2018
+ name = "moving_avg"
2019
+
2020
+ def __init__(self, **kwargs: Any):
2021
+ super().__init__(**kwargs)
2022
+
2023
+
2024
+ class LinearMovingAverageAggregation(MovingAvg[_R]):
2025
+ """
2026
+ :arg model: (required)
2027
+ :arg settings: (required)
2028
+ :arg minimize:
2029
+ :arg predict:
2030
+ :arg window:
2031
+ :arg format: `DecimalFormat` pattern for the output value. If
2032
+ specified, the formatted value is returned in the aggregation’s
2033
+ `value_as_string` property.
2034
+ :arg gap_policy: Policy to apply when gaps are found in the data.
2035
+ Defaults to `skip` if omitted.
2036
+ :arg buckets_path: Path to the buckets that contain one set of values
2037
+ to correlate.
2038
+ """
2039
+
2040
+ def __init__(
2041
+ self,
2042
+ *,
2043
+ model: Any = DEFAULT,
2044
+ settings: Union["types.EmptyObject", Dict[str, Any], "DefaultType"] = DEFAULT,
2045
+ minimize: Union[bool, "DefaultType"] = DEFAULT,
2046
+ predict: Union[int, "DefaultType"] = DEFAULT,
2047
+ window: Union[int, "DefaultType"] = DEFAULT,
2048
+ format: Union[str, "DefaultType"] = DEFAULT,
2049
+ gap_policy: Union[
2050
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
2051
+ ] = DEFAULT,
2052
+ buckets_path: Union[
2053
+ str, Sequence[str], Mapping[str, str], "DefaultType"
2054
+ ] = DEFAULT,
2055
+ **kwargs: Any,
2056
+ ):
2057
+ super().__init__(
2058
+ model=model,
2059
+ settings=settings,
2060
+ minimize=minimize,
2061
+ predict=predict,
2062
+ window=window,
2063
+ format=format,
2064
+ gap_policy=gap_policy,
2065
+ buckets_path=buckets_path,
2066
+ **kwargs,
2067
+ )
2068
+
2069
+
2070
+ class SimpleMovingAverageAggregation(MovingAvg[_R]):
2071
+ """
2072
+ :arg model: (required)
2073
+ :arg settings: (required)
2074
+ :arg minimize:
2075
+ :arg predict:
2076
+ :arg window:
2077
+ :arg format: `DecimalFormat` pattern for the output value. If
2078
+ specified, the formatted value is returned in the aggregation’s
2079
+ `value_as_string` property.
2080
+ :arg gap_policy: Policy to apply when gaps are found in the data.
2081
+ Defaults to `skip` if omitted.
2082
+ :arg buckets_path: Path to the buckets that contain one set of values
2083
+ to correlate.
2084
+ """
2085
+
2086
+ def __init__(
2087
+ self,
2088
+ *,
2089
+ model: Any = DEFAULT,
2090
+ settings: Union["types.EmptyObject", Dict[str, Any], "DefaultType"] = DEFAULT,
2091
+ minimize: Union[bool, "DefaultType"] = DEFAULT,
2092
+ predict: Union[int, "DefaultType"] = DEFAULT,
2093
+ window: Union[int, "DefaultType"] = DEFAULT,
2094
+ format: Union[str, "DefaultType"] = DEFAULT,
2095
+ gap_policy: Union[
2096
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
2097
+ ] = DEFAULT,
2098
+ buckets_path: Union[
2099
+ str, Sequence[str], Mapping[str, str], "DefaultType"
2100
+ ] = DEFAULT,
2101
+ **kwargs: Any,
2102
+ ):
2103
+ super().__init__(
2104
+ model=model,
2105
+ settings=settings,
2106
+ minimize=minimize,
2107
+ predict=predict,
2108
+ window=window,
2109
+ format=format,
2110
+ gap_policy=gap_policy,
2111
+ buckets_path=buckets_path,
2112
+ **kwargs,
2113
+ )
2114
+
2115
+
2116
+ class EwmaMovingAverageAggregation(MovingAvg[_R]):
2117
+ """
2118
+ :arg model: (required)
2119
+ :arg settings: (required)
2120
+ :arg minimize:
2121
+ :arg predict:
2122
+ :arg window:
2123
+ :arg format: `DecimalFormat` pattern for the output value. If
2124
+ specified, the formatted value is returned in the aggregation’s
2125
+ `value_as_string` property.
2126
+ :arg gap_policy: Policy to apply when gaps are found in the data.
2127
+ Defaults to `skip` if omitted.
2128
+ :arg buckets_path: Path to the buckets that contain one set of values
2129
+ to correlate.
2130
+ """
2131
+
2132
+ def __init__(
2133
+ self,
2134
+ *,
2135
+ model: Any = DEFAULT,
2136
+ settings: Union[
2137
+ "types.EwmaModelSettings", Dict[str, Any], "DefaultType"
2138
+ ] = DEFAULT,
2139
+ minimize: Union[bool, "DefaultType"] = DEFAULT,
2140
+ predict: Union[int, "DefaultType"] = DEFAULT,
2141
+ window: Union[int, "DefaultType"] = DEFAULT,
2142
+ format: Union[str, "DefaultType"] = DEFAULT,
2143
+ gap_policy: Union[
2144
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
2145
+ ] = DEFAULT,
2146
+ buckets_path: Union[
2147
+ str, Sequence[str], Mapping[str, str], "DefaultType"
2148
+ ] = DEFAULT,
2149
+ **kwargs: Any,
2150
+ ):
2151
+ super().__init__(
2152
+ model=model,
2153
+ settings=settings,
2154
+ minimize=minimize,
2155
+ predict=predict,
2156
+ window=window,
2157
+ format=format,
2158
+ gap_policy=gap_policy,
2159
+ buckets_path=buckets_path,
2160
+ **kwargs,
2161
+ )
2162
+
2163
+
2164
+ class HoltMovingAverageAggregation(MovingAvg[_R]):
2165
+ """
2166
+ :arg model: (required)
2167
+ :arg settings: (required)
2168
+ :arg minimize:
2169
+ :arg predict:
2170
+ :arg window:
2171
+ :arg format: `DecimalFormat` pattern for the output value. If
2172
+ specified, the formatted value is returned in the aggregation’s
2173
+ `value_as_string` property.
2174
+ :arg gap_policy: Policy to apply when gaps are found in the data.
2175
+ Defaults to `skip` if omitted.
2176
+ :arg buckets_path: Path to the buckets that contain one set of values
2177
+ to correlate.
2178
+ """
2179
+
2180
+ def __init__(
2181
+ self,
2182
+ *,
2183
+ model: Any = DEFAULT,
2184
+ settings: Union[
2185
+ "types.HoltLinearModelSettings", Dict[str, Any], "DefaultType"
2186
+ ] = DEFAULT,
2187
+ minimize: Union[bool, "DefaultType"] = DEFAULT,
2188
+ predict: Union[int, "DefaultType"] = DEFAULT,
2189
+ window: Union[int, "DefaultType"] = DEFAULT,
2190
+ format: Union[str, "DefaultType"] = DEFAULT,
2191
+ gap_policy: Union[
2192
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
2193
+ ] = DEFAULT,
2194
+ buckets_path: Union[
2195
+ str, Sequence[str], Mapping[str, str], "DefaultType"
2196
+ ] = DEFAULT,
2197
+ **kwargs: Any,
2198
+ ):
2199
+ super().__init__(
2200
+ model=model,
2201
+ settings=settings,
2202
+ minimize=minimize,
2203
+ predict=predict,
2204
+ window=window,
2205
+ format=format,
2206
+ gap_policy=gap_policy,
2207
+ buckets_path=buckets_path,
2208
+ **kwargs,
2209
+ )
2210
+
2211
+
2212
+ class HoltWintersMovingAverageAggregation(MovingAvg[_R]):
2213
+ """
2214
+ :arg model: (required)
2215
+ :arg settings: (required)
2216
+ :arg minimize:
2217
+ :arg predict:
2218
+ :arg window:
2219
+ :arg format: `DecimalFormat` pattern for the output value. If
2220
+ specified, the formatted value is returned in the aggregation’s
2221
+ `value_as_string` property.
2222
+ :arg gap_policy: Policy to apply when gaps are found in the data.
2223
+ Defaults to `skip` if omitted.
2224
+ :arg buckets_path: Path to the buckets that contain one set of values
2225
+ to correlate.
2226
+ """
2227
+
2228
+ def __init__(
2229
+ self,
2230
+ *,
2231
+ model: Any = DEFAULT,
2232
+ settings: Union[
2233
+ "types.HoltWintersModelSettings", Dict[str, Any], "DefaultType"
2234
+ ] = DEFAULT,
2235
+ minimize: Union[bool, "DefaultType"] = DEFAULT,
2236
+ predict: Union[int, "DefaultType"] = DEFAULT,
2237
+ window: Union[int, "DefaultType"] = DEFAULT,
2238
+ format: Union[str, "DefaultType"] = DEFAULT,
2239
+ gap_policy: Union[
2240
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
2241
+ ] = DEFAULT,
2242
+ buckets_path: Union[
2243
+ str, Sequence[str], Mapping[str, str], "DefaultType"
2244
+ ] = DEFAULT,
2245
+ **kwargs: Any,
2246
+ ):
2247
+ super().__init__(
2248
+ model=model,
2249
+ settings=settings,
2250
+ minimize=minimize,
2251
+ predict=predict,
2252
+ window=window,
2253
+ format=format,
2254
+ gap_policy=gap_policy,
2255
+ buckets_path=buckets_path,
2256
+ **kwargs,
2257
+ )
2258
+
2259
+
2260
+ class MovingPercentiles(Pipeline[_R]):
2261
+ """
2262
+ Given an ordered series of percentiles, "slides" a window across those
2263
+ percentiles and computes cumulative percentiles.
2264
+
2265
+ :arg window: The size of window to "slide" across the histogram.
2266
+ :arg shift: By default, the window consists of the last n values
2267
+ excluding the current bucket. Increasing `shift` by 1, moves the
2268
+ starting window position by 1 to the right.
2269
+ :arg keyed:
2270
+ :arg format: `DecimalFormat` pattern for the output value. If
2271
+ specified, the formatted value is returned in the aggregation’s
2272
+ `value_as_string` property.
2273
+ :arg gap_policy: Policy to apply when gaps are found in the data.
2274
+ Defaults to `skip` if omitted.
2275
+ :arg buckets_path: Path to the buckets that contain one set of values
2276
+ to correlate.
2277
+ """
2278
+
2279
+ name = "moving_percentiles"
2280
+
2281
+ def __init__(
2282
+ self,
2283
+ *,
2284
+ window: Union[int, "DefaultType"] = DEFAULT,
2285
+ shift: Union[int, "DefaultType"] = DEFAULT,
2286
+ keyed: Union[bool, "DefaultType"] = DEFAULT,
2287
+ format: Union[str, "DefaultType"] = DEFAULT,
2288
+ gap_policy: Union[
2289
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
2290
+ ] = DEFAULT,
2291
+ buckets_path: Union[
2292
+ str, Sequence[str], Mapping[str, str], "DefaultType"
2293
+ ] = DEFAULT,
2294
+ **kwargs: Any,
2295
+ ):
2296
+ super().__init__(
2297
+ window=window,
2298
+ shift=shift,
2299
+ keyed=keyed,
2300
+ format=format,
2301
+ gap_policy=gap_policy,
2302
+ buckets_path=buckets_path,
2303
+ **kwargs,
2304
+ )
2305
+
2306
+
2307
+ class MovingFn(Pipeline[_R]):
2308
+ """
2309
+ Given an ordered series of data, "slides" a window across the data and
2310
+ runs a custom script on each window of data. For convenience, a number
2311
+ of common functions are predefined such as `min`, `max`, and moving
2312
+ averages.
2313
+
2314
+ :arg script: The script that should be executed on each window of
2315
+ data.
2316
+ :arg shift: By default, the window consists of the last n values
2317
+ excluding the current bucket. Increasing `shift` by 1, moves the
2318
+ starting window position by 1 to the right.
2319
+ :arg window: The size of window to "slide" across the histogram.
2320
+ :arg format: `DecimalFormat` pattern for the output value. If
2321
+ specified, the formatted value is returned in the aggregation’s
2322
+ `value_as_string` property.
2323
+ :arg gap_policy: Policy to apply when gaps are found in the data.
2324
+ Defaults to `skip` if omitted.
2325
+ :arg buckets_path: Path to the buckets that contain one set of values
2326
+ to correlate.
2327
+ """
2328
+
2329
+ name = "moving_fn"
2330
+
2331
+ def __init__(
2332
+ self,
2333
+ *,
2334
+ script: Union[str, "DefaultType"] = DEFAULT,
2335
+ shift: Union[int, "DefaultType"] = DEFAULT,
2336
+ window: Union[int, "DefaultType"] = DEFAULT,
2337
+ format: Union[str, "DefaultType"] = DEFAULT,
2338
+ gap_policy: Union[
2339
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
2340
+ ] = DEFAULT,
2341
+ buckets_path: Union[
2342
+ str, Sequence[str], Mapping[str, str], "DefaultType"
2343
+ ] = DEFAULT,
2344
+ **kwargs: Any,
2345
+ ):
2346
+ super().__init__(
2347
+ script=script,
2348
+ shift=shift,
2349
+ window=window,
2350
+ format=format,
2351
+ gap_policy=gap_policy,
2352
+ buckets_path=buckets_path,
2353
+ **kwargs,
2354
+ )
2355
+
2356
+
2357
+ class MultiTerms(Bucket[_R]):
2358
+ """
2359
+ A multi-bucket value source based aggregation where buckets are
2360
+ dynamically built - one per unique set of values.
2361
+
2362
+ :arg terms: (required) The field from which to generate sets of terms.
2363
+ :arg collect_mode: Specifies the strategy for data collection.
2364
+ Defaults to `breadth_first` if omitted.
2365
+ :arg order: Specifies the sort order of the buckets. Defaults to
2366
+ sorting by descending document count.
2367
+ :arg min_doc_count: The minimum number of documents in a bucket for it
2368
+ to be returned. Defaults to `1` if omitted.
2369
+ :arg shard_min_doc_count: The minimum number of documents in a bucket
2370
+ on each shard for it to be returned. Defaults to `1` if omitted.
2371
+ :arg shard_size: The number of candidate terms produced by each shard.
2372
+ By default, `shard_size` will be automatically estimated based on
2373
+ the number of shards and the `size` parameter.
2374
+ :arg show_term_doc_count_error: Calculates the doc count error on per
2375
+ term basis.
2376
+ :arg size: The number of term buckets should be returned out of the
2377
+ overall terms list. Defaults to `10` if omitted.
2378
+ """
2379
+
2380
+ name = "multi_terms"
2381
+
2382
+ def __init__(
2383
+ self,
2384
+ *,
2385
+ terms: Union[
2386
+ Sequence["types.MultiTermLookup"], Sequence[Dict[str, Any]], "DefaultType"
2387
+ ] = DEFAULT,
2388
+ collect_mode: Union[
2389
+ Literal["depth_first", "breadth_first"], "DefaultType"
2390
+ ] = DEFAULT,
2391
+ order: Union[
2392
+ Mapping[Union[str, "InstrumentedField"], Literal["asc", "desc"]],
2393
+ Sequence[Mapping[Union[str, "InstrumentedField"], Literal["asc", "desc"]]],
2394
+ "DefaultType",
2395
+ ] = DEFAULT,
2396
+ min_doc_count: Union[int, "DefaultType"] = DEFAULT,
2397
+ shard_min_doc_count: Union[int, "DefaultType"] = DEFAULT,
2398
+ shard_size: Union[int, "DefaultType"] = DEFAULT,
2399
+ show_term_doc_count_error: Union[bool, "DefaultType"] = DEFAULT,
2400
+ size: Union[int, "DefaultType"] = DEFAULT,
2401
+ **kwargs: Any,
2402
+ ):
2403
+ super().__init__(
2404
+ terms=terms,
2405
+ collect_mode=collect_mode,
2406
+ order=order,
2407
+ min_doc_count=min_doc_count,
2408
+ shard_min_doc_count=shard_min_doc_count,
2409
+ shard_size=shard_size,
2410
+ show_term_doc_count_error=show_term_doc_count_error,
2411
+ size=size,
2412
+ **kwargs,
2413
+ )
2414
+
2415
+
2416
+ class Nested(Bucket[_R]):
2417
+ """
2418
+ A special single bucket aggregation that enables aggregating nested
2419
+ documents.
2420
+
2421
+ :arg path: The path to the field of type `nested`.
2422
+ """
2423
+
2424
+ name = "nested"
2425
+
2426
+ def __init__(
2427
+ self,
2428
+ path: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
2429
+ **kwargs: Any,
2430
+ ):
2431
+ super().__init__(path=path, **kwargs)
2432
+
2433
+
2434
+ class Normalize(Pipeline[_R]):
2435
+ """
2436
+ A parent pipeline aggregation which calculates the specific
2437
+ normalized/rescaled value for a specific bucket value.
2438
+
2439
+ :arg method: The specific method to apply.
2440
+ :arg format: `DecimalFormat` pattern for the output value. If
2441
+ specified, the formatted value is returned in the aggregation’s
2442
+ `value_as_string` property.
2443
+ :arg gap_policy: Policy to apply when gaps are found in the data.
2444
+ Defaults to `skip` if omitted.
2445
+ :arg buckets_path: Path to the buckets that contain one set of values
2446
+ to correlate.
2447
+ """
2448
+
2449
+ name = "normalize"
2450
+
2451
+ def __init__(
2452
+ self,
2453
+ *,
2454
+ method: Union[
2455
+ Literal[
2456
+ "rescale_0_1",
2457
+ "rescale_0_100",
2458
+ "percent_of_sum",
2459
+ "mean",
2460
+ "z-score",
2461
+ "softmax",
2462
+ ],
2463
+ "DefaultType",
2464
+ ] = DEFAULT,
2465
+ format: Union[str, "DefaultType"] = DEFAULT,
2466
+ gap_policy: Union[
2467
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
2468
+ ] = DEFAULT,
2469
+ buckets_path: Union[
2470
+ str, Sequence[str], Mapping[str, str], "DefaultType"
2471
+ ] = DEFAULT,
2472
+ **kwargs: Any,
2473
+ ):
2474
+ super().__init__(
2475
+ method=method,
2476
+ format=format,
2477
+ gap_policy=gap_policy,
2478
+ buckets_path=buckets_path,
2479
+ **kwargs,
2480
+ )
2481
+
2482
+
2483
+ class Parent(Bucket[_R]):
2484
+ """
2485
+ A special single bucket aggregation that selects parent documents that
2486
+ have the specified type, as defined in a `join` field.
2487
+
2488
+ :arg type: The child type that should be selected.
2489
+ """
2490
+
2491
+ name = "parent"
2492
+
2493
+ def __init__(self, type: Union[str, "DefaultType"] = DEFAULT, **kwargs: Any):
2494
+ super().__init__(type=type, **kwargs)
2495
+
2496
+
2497
+ class PercentileRanks(Agg[_R]):
2498
+ """
2499
+ A multi-value metrics aggregation that calculates one or more
2500
+ percentile ranks over numeric values extracted from the aggregated
2501
+ documents.
2502
+
2503
+ :arg keyed: By default, the aggregation associates a unique string key
2504
+ with each bucket and returns the ranges as a hash rather than an
2505
+ array. Set to `false` to disable this behavior. Defaults to `True`
2506
+ if omitted.
2507
+ :arg values: An array of values for which to calculate the percentile
2508
+ ranks.
2509
+ :arg hdr: Uses the alternative High Dynamic Range Histogram algorithm
2510
+ to calculate percentile ranks.
2511
+ :arg tdigest: Sets parameters for the default TDigest algorithm used
2512
+ to calculate percentile ranks.
2513
+ :arg format:
2514
+ :arg field: The field on which to run the aggregation.
2515
+ :arg missing: The value to apply to documents that do not have a
2516
+ value. By default, documents without a value are ignored.
2517
+ :arg script:
2518
+ """
2519
+
2520
+ name = "percentile_ranks"
2521
+
2522
+ def __init__(
2523
+ self,
2524
+ *,
2525
+ keyed: Union[bool, "DefaultType"] = DEFAULT,
2526
+ values: Union[Sequence[float], None, "DefaultType"] = DEFAULT,
2527
+ hdr: Union["types.HdrMethod", Dict[str, Any], "DefaultType"] = DEFAULT,
2528
+ tdigest: Union["types.TDigest", Dict[str, Any], "DefaultType"] = DEFAULT,
2529
+ format: Union[str, "DefaultType"] = DEFAULT,
2530
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
2531
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
2532
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
2533
+ **kwargs: Any,
2534
+ ):
2535
+ super().__init__(
2536
+ keyed=keyed,
2537
+ values=values,
2538
+ hdr=hdr,
2539
+ tdigest=tdigest,
2540
+ format=format,
2541
+ field=field,
2542
+ missing=missing,
2543
+ script=script,
2544
+ **kwargs,
2545
+ )
2546
+
2547
+
2548
+ class Percentiles(Agg[_R]):
2549
+ """
2550
+ A multi-value metrics aggregation that calculates one or more
2551
+ percentiles over numeric values extracted from the aggregated
2552
+ documents.
2553
+
2554
+ :arg keyed: By default, the aggregation associates a unique string key
2555
+ with each bucket and returns the ranges as a hash rather than an
2556
+ array. Set to `false` to disable this behavior. Defaults to `True`
2557
+ if omitted.
2558
+ :arg percents: The percentiles to calculate.
2559
+ :arg hdr: Uses the alternative High Dynamic Range Histogram algorithm
2560
+ to calculate percentiles.
2561
+ :arg tdigest: Sets parameters for the default TDigest algorithm used
2562
+ to calculate percentiles.
2563
+ :arg format:
2564
+ :arg field: The field on which to run the aggregation.
2565
+ :arg missing: The value to apply to documents that do not have a
2566
+ value. By default, documents without a value are ignored.
2567
+ :arg script:
2568
+ """
2569
+
2570
+ name = "percentiles"
2571
+
2572
+ def __init__(
2573
+ self,
2574
+ *,
2575
+ keyed: Union[bool, "DefaultType"] = DEFAULT,
2576
+ percents: Union[Sequence[float], "DefaultType"] = DEFAULT,
2577
+ hdr: Union["types.HdrMethod", Dict[str, Any], "DefaultType"] = DEFAULT,
2578
+ tdigest: Union["types.TDigest", Dict[str, Any], "DefaultType"] = DEFAULT,
2579
+ format: Union[str, "DefaultType"] = DEFAULT,
2580
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
2581
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
2582
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
2583
+ **kwargs: Any,
2584
+ ):
2585
+ super().__init__(
2586
+ keyed=keyed,
2587
+ percents=percents,
2588
+ hdr=hdr,
2589
+ tdigest=tdigest,
2590
+ format=format,
2591
+ field=field,
2592
+ missing=missing,
2593
+ script=script,
2594
+ **kwargs,
2595
+ )
2596
+
2597
+
2598
+ class PercentilesBucket(Pipeline[_R]):
2599
+ """
2600
+ A sibling pipeline aggregation which calculates percentiles across all
2601
+ bucket of a specified metric in a sibling aggregation.
2602
+
2603
+ :arg percents: The list of percentiles to calculate.
2604
+ :arg format: `DecimalFormat` pattern for the output value. If
2605
+ specified, the formatted value is returned in the aggregation’s
2606
+ `value_as_string` property.
2607
+ :arg gap_policy: Policy to apply when gaps are found in the data.
2608
+ Defaults to `skip` if omitted.
2609
+ :arg buckets_path: Path to the buckets that contain one set of values
2610
+ to correlate.
2611
+ """
2612
+
2613
+ name = "percentiles_bucket"
2614
+
2615
+ def __init__(
2616
+ self,
2617
+ *,
2618
+ percents: Union[Sequence[float], "DefaultType"] = DEFAULT,
2619
+ format: Union[str, "DefaultType"] = DEFAULT,
2620
+ gap_policy: Union[
2621
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
2622
+ ] = DEFAULT,
2623
+ buckets_path: Union[
2624
+ str, Sequence[str], Mapping[str, str], "DefaultType"
2625
+ ] = DEFAULT,
2626
+ **kwargs: Any,
2627
+ ):
2628
+ super().__init__(
2629
+ percents=percents,
2630
+ format=format,
2631
+ gap_policy=gap_policy,
2632
+ buckets_path=buckets_path,
2633
+ **kwargs,
2634
+ )
2635
+
2636
+
2637
+ class Range(Bucket[_R]):
2638
+ """
2639
+ A multi-bucket value source based aggregation that enables the user to
2640
+ define a set of ranges - each representing a bucket.
2641
+
2642
+ :arg field: The date field whose values are use to build ranges.
2643
+ :arg missing: The value to apply to documents that do not have a
2644
+ value. By default, documents without a value are ignored.
2645
+ :arg ranges: An array of ranges used to bucket documents.
2646
+ :arg script:
2647
+ :arg keyed: Set to `true` to associate a unique string key with each
2648
+ bucket and return the ranges as a hash rather than an array.
2649
+ :arg format:
2650
+ """
2651
+
2652
+ name = "range"
2653
+
2654
+ def __init__(
2655
+ self,
2656
+ *,
2657
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
2658
+ missing: Union[int, "DefaultType"] = DEFAULT,
2659
+ ranges: Union[
2660
+ Sequence["types.AggregationRange"], Sequence[Dict[str, Any]], "DefaultType"
2661
+ ] = DEFAULT,
2662
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
2663
+ keyed: Union[bool, "DefaultType"] = DEFAULT,
2664
+ format: Union[str, "DefaultType"] = DEFAULT,
2665
+ **kwargs: Any,
2666
+ ):
2667
+ super().__init__(
2668
+ field=field,
2669
+ missing=missing,
2670
+ ranges=ranges,
2671
+ script=script,
2672
+ keyed=keyed,
2673
+ format=format,
2674
+ **kwargs,
2675
+ )
2676
+
2677
+
2678
+ class RareTerms(Bucket[_R]):
2679
+ """
2680
+ A multi-bucket value source based aggregation which finds "rare"
2681
+ terms — terms that are at the long-tail of the distribution and are
2682
+ not frequent.
2683
+
2684
+ :arg exclude: Terms that should be excluded from the aggregation.
2685
+ :arg field: The field from which to return rare terms.
2686
+ :arg include: Terms that should be included in the aggregation.
2687
+ :arg max_doc_count: The maximum number of documents a term should
2688
+ appear in. Defaults to `1` if omitted.
2689
+ :arg missing: The value to apply to documents that do not have a
2690
+ value. By default, documents without a value are ignored.
2691
+ :arg precision: The precision of the internal CuckooFilters. Smaller
2692
+ precision leads to better approximation, but higher memory usage.
2693
+ Defaults to `0.001` if omitted.
2694
+ :arg value_type:
2695
+ """
2696
+
2697
+ name = "rare_terms"
2698
+
2699
+ def __init__(
2700
+ self,
2701
+ *,
2702
+ exclude: Union[str, Sequence[str], "DefaultType"] = DEFAULT,
2703
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
2704
+ include: Union[
2705
+ str, Sequence[str], "types.TermsPartition", Dict[str, Any], "DefaultType"
2706
+ ] = DEFAULT,
2707
+ max_doc_count: Union[int, "DefaultType"] = DEFAULT,
2708
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
2709
+ precision: Union[float, "DefaultType"] = DEFAULT,
2710
+ value_type: Union[str, "DefaultType"] = DEFAULT,
2711
+ **kwargs: Any,
2712
+ ):
2713
+ super().__init__(
2714
+ exclude=exclude,
2715
+ field=field,
2716
+ include=include,
2717
+ max_doc_count=max_doc_count,
2718
+ missing=missing,
2719
+ precision=precision,
2720
+ value_type=value_type,
2721
+ **kwargs,
2722
+ )
2723
+
2724
+
2725
+ class Rate(Agg[_R]):
2726
+ """
2727
+ Calculates a rate of documents or a field in each bucket. Can only be
2728
+ used inside a `date_histogram` or `composite` aggregation.
2729
+
2730
+ :arg unit: The interval used to calculate the rate. By default, the
2731
+ interval of the `date_histogram` is used.
2732
+ :arg mode: How the rate is calculated. Defaults to `sum` if omitted.
2733
+ :arg format:
2734
+ :arg field: The field on which to run the aggregation.
2735
+ :arg missing: The value to apply to documents that do not have a
2736
+ value. By default, documents without a value are ignored.
2737
+ :arg script:
2738
+ """
2739
+
2740
+ name = "rate"
2741
+
2742
+ def __init__(
2743
+ self,
2744
+ *,
2745
+ unit: Union[
2746
+ Literal[
2747
+ "second", "minute", "hour", "day", "week", "month", "quarter", "year"
2748
+ ],
2749
+ "DefaultType",
2750
+ ] = DEFAULT,
2751
+ mode: Union[Literal["sum", "value_count"], "DefaultType"] = DEFAULT,
2752
+ format: Union[str, "DefaultType"] = DEFAULT,
2753
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
2754
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
2755
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
2756
+ **kwargs: Any,
2757
+ ):
2758
+ super().__init__(
2759
+ unit=unit,
2760
+ mode=mode,
2761
+ format=format,
2762
+ field=field,
2763
+ missing=missing,
2764
+ script=script,
2765
+ **kwargs,
2766
+ )
2767
+
2768
+
2769
+ class ReverseNested(Bucket[_R]):
2770
+ """
2771
+ A special single bucket aggregation that enables aggregating on parent
2772
+ documents from nested documents. Should only be defined inside a
2773
+ `nested` aggregation.
2774
+
2775
+ :arg path: Defines the nested object field that should be joined back
2776
+ to. The default is empty, which means that it joins back to the
2777
+ root/main document level.
2778
+ """
2779
+
2780
+ name = "reverse_nested"
2781
+
2782
+ def __init__(
2783
+ self,
2784
+ path: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
2785
+ **kwargs: Any,
2786
+ ):
2787
+ super().__init__(path=path, **kwargs)
2788
+
2789
+
2790
+ class RandomSampler(Bucket[_R]):
2791
+ """
2792
+ A single bucket aggregation that randomly includes documents in the
2793
+ aggregated results. Sampling provides significant speed improvement at
2794
+ the cost of accuracy.
2795
+
2796
+ :arg probability: (required) The probability that a document will be
2797
+ included in the aggregated data. Must be greater than 0, less than
2798
+ 0.5, or exactly 1. The lower the probability, the fewer documents
2799
+ are matched.
2800
+ :arg seed: The seed to generate the random sampling of documents. When
2801
+ a seed is provided, the random subset of documents is the same
2802
+ between calls.
2803
+ :arg shard_seed: When combined with seed, setting shard_seed ensures
2804
+ 100% consistent sampling over shards where data is exactly the
2805
+ same.
2806
+ """
2807
+
2808
+ name = "random_sampler"
2809
+
2810
+ def __init__(
2811
+ self,
2812
+ *,
2813
+ probability: Union[float, "DefaultType"] = DEFAULT,
2814
+ seed: Union[int, "DefaultType"] = DEFAULT,
2815
+ shard_seed: Union[int, "DefaultType"] = DEFAULT,
2816
+ **kwargs: Any,
2817
+ ):
2818
+ super().__init__(
2819
+ probability=probability, seed=seed, shard_seed=shard_seed, **kwargs
2820
+ )
2821
+
2822
+
2823
+ class Sampler(Bucket[_R]):
2824
+ """
2825
+ A filtering aggregation used to limit any sub aggregations' processing
2826
+ to a sample of the top-scoring documents.
2827
+
2828
+ :arg shard_size: Limits how many top-scoring documents are collected
2829
+ in the sample processed on each shard. Defaults to `100` if
2830
+ omitted.
2831
+ """
2832
+
2833
+ name = "sampler"
2834
+
2835
+ def __init__(self, shard_size: Union[int, "DefaultType"] = DEFAULT, **kwargs: Any):
2836
+ super().__init__(shard_size=shard_size, **kwargs)
2837
+
2838
+
2839
+ class ScriptedMetric(Agg[_R]):
2840
+ """
2841
+ A metric aggregation that uses scripts to provide a metric output.
2842
+
2843
+ :arg combine_script: Runs once on each shard after document collection
2844
+ is complete. Allows the aggregation to consolidate the state
2845
+ returned from each shard.
2846
+ :arg init_script: Runs prior to any collection of documents. Allows
2847
+ the aggregation to set up any initial state.
2848
+ :arg map_script: Run once per document collected. If no
2849
+ `combine_script` is specified, the resulting state needs to be
2850
+ stored in the `state` object.
2851
+ :arg params: A global object with script parameters for `init`, `map`
2852
+ and `combine` scripts. It is shared between the scripts.
2853
+ :arg reduce_script: Runs once on the coordinating node after all
2854
+ shards have returned their results. The script is provided with
2855
+ access to a variable `states`, which is an array of the result of
2856
+ the `combine_script` on each shard.
2857
+ :arg field: The field on which to run the aggregation.
2858
+ :arg missing: The value to apply to documents that do not have a
2859
+ value. By default, documents without a value are ignored.
2860
+ :arg script:
2861
+ """
2862
+
2863
+ name = "scripted_metric"
2864
+
2865
+ def __init__(
2866
+ self,
2867
+ *,
2868
+ combine_script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
2869
+ init_script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
2870
+ map_script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
2871
+ params: Union[Mapping[str, Any], "DefaultType"] = DEFAULT,
2872
+ reduce_script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
2873
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
2874
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
2875
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
2876
+ **kwargs: Any,
2877
+ ):
2878
+ super().__init__(
2879
+ combine_script=combine_script,
2880
+ init_script=init_script,
2881
+ map_script=map_script,
2882
+ params=params,
2883
+ reduce_script=reduce_script,
2884
+ field=field,
2885
+ missing=missing,
2886
+ script=script,
2887
+ **kwargs,
2888
+ )
2889
+
2890
+
2891
+ class SerialDiff(Pipeline[_R]):
2892
+ """
2893
+ An aggregation that subtracts values in a time series from themselves
2894
+ at different time lags or periods.
2895
+
2896
+ :arg lag: The historical bucket to subtract from the current value.
2897
+ Must be a positive, non-zero integer.
2898
+ :arg format: `DecimalFormat` pattern for the output value. If
2899
+ specified, the formatted value is returned in the aggregation’s
2900
+ `value_as_string` property.
2901
+ :arg gap_policy: Policy to apply when gaps are found in the data.
2902
+ Defaults to `skip` if omitted.
2903
+ :arg buckets_path: Path to the buckets that contain one set of values
2904
+ to correlate.
2905
+ """
2906
+
2907
+ name = "serial_diff"
2908
+
2909
+ def __init__(
2910
+ self,
2911
+ *,
2912
+ lag: Union[int, "DefaultType"] = DEFAULT,
2913
+ format: Union[str, "DefaultType"] = DEFAULT,
2914
+ gap_policy: Union[
2915
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
2916
+ ] = DEFAULT,
2917
+ buckets_path: Union[
2918
+ str, Sequence[str], Mapping[str, str], "DefaultType"
2919
+ ] = DEFAULT,
2920
+ **kwargs: Any,
2921
+ ):
2922
+ super().__init__(
2923
+ lag=lag,
2924
+ format=format,
2925
+ gap_policy=gap_policy,
2926
+ buckets_path=buckets_path,
2927
+ **kwargs,
2928
+ )
2929
+
2930
+
2931
+ class SignificantTerms(Bucket[_R]):
2932
+ """
2933
+ Returns interesting or unusual occurrences of terms in a set.
2934
+
2935
+ :arg background_filter: A background filter that can be used to focus
2936
+ in on significant terms within a narrower context, instead of the
2937
+ entire index.
2938
+ :arg chi_square: Use Chi square, as described in "Information
2939
+ Retrieval", Manning et al., Chapter 13.5.2, as the significance
2940
+ score.
2941
+ :arg exclude: Terms to exclude.
2942
+ :arg execution_hint: Mechanism by which the aggregation should be
2943
+ executed: using field values directly or using global ordinals.
2944
+ :arg field: The field from which to return significant terms.
2945
+ :arg gnd: Use Google normalized distance as described in "The Google
2946
+ Similarity Distance", Cilibrasi and Vitanyi, 2007, as the
2947
+ significance score.
2948
+ :arg include: Terms to include.
2949
+ :arg jlh: Use JLH score as the significance score.
2950
+ :arg min_doc_count: Only return terms that are found in more than
2951
+ `min_doc_count` hits. Defaults to `3` if omitted.
2952
+ :arg mutual_information: Use mutual information as described in
2953
+ "Information Retrieval", Manning et al., Chapter 13.5.1, as the
2954
+ significance score.
2955
+ :arg percentage: A simple calculation of the number of documents in
2956
+ the foreground sample with a term divided by the number of
2957
+ documents in the background with the term.
2958
+ :arg script_heuristic: Customized score, implemented via a script.
2959
+ :arg shard_min_doc_count: Regulates the certainty a shard has if the
2960
+ term should actually be added to the candidate list or not with
2961
+ respect to the `min_doc_count`. Terms will only be considered if
2962
+ their local shard frequency within the set is higher than the
2963
+ `shard_min_doc_count`.
2964
+ :arg shard_size: Can be used to control the volumes of candidate terms
2965
+ produced by each shard. By default, `shard_size` will be
2966
+ automatically estimated based on the number of shards and the
2967
+ `size` parameter.
2968
+ :arg size: The number of buckets returned out of the overall terms
2969
+ list.
2970
+ """
2971
+
2972
+ name = "significant_terms"
2973
+ _param_defs = {
2974
+ "background_filter": {"type": "query"},
2975
+ }
2976
+
2977
+ def __init__(
2978
+ self,
2979
+ *,
2980
+ background_filter: Union[Query, "DefaultType"] = DEFAULT,
2981
+ chi_square: Union[
2982
+ "types.ChiSquareHeuristic", Dict[str, Any], "DefaultType"
2983
+ ] = DEFAULT,
2984
+ exclude: Union[str, Sequence[str], "DefaultType"] = DEFAULT,
2985
+ execution_hint: Union[
2986
+ Literal[
2987
+ "map",
2988
+ "global_ordinals",
2989
+ "global_ordinals_hash",
2990
+ "global_ordinals_low_cardinality",
2991
+ ],
2992
+ "DefaultType",
2993
+ ] = DEFAULT,
2994
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
2995
+ gnd: Union[
2996
+ "types.GoogleNormalizedDistanceHeuristic", Dict[str, Any], "DefaultType"
2997
+ ] = DEFAULT,
2998
+ include: Union[
2999
+ str, Sequence[str], "types.TermsPartition", Dict[str, Any], "DefaultType"
3000
+ ] = DEFAULT,
3001
+ jlh: Union["types.EmptyObject", Dict[str, Any], "DefaultType"] = DEFAULT,
3002
+ min_doc_count: Union[int, "DefaultType"] = DEFAULT,
3003
+ mutual_information: Union[
3004
+ "types.MutualInformationHeuristic", Dict[str, Any], "DefaultType"
3005
+ ] = DEFAULT,
3006
+ percentage: Union[
3007
+ "types.PercentageScoreHeuristic", Dict[str, Any], "DefaultType"
3008
+ ] = DEFAULT,
3009
+ script_heuristic: Union[
3010
+ "types.ScriptedHeuristic", Dict[str, Any], "DefaultType"
3011
+ ] = DEFAULT,
3012
+ shard_min_doc_count: Union[int, "DefaultType"] = DEFAULT,
3013
+ shard_size: Union[int, "DefaultType"] = DEFAULT,
3014
+ size: Union[int, "DefaultType"] = DEFAULT,
3015
+ **kwargs: Any,
3016
+ ):
3017
+ super().__init__(
3018
+ background_filter=background_filter,
3019
+ chi_square=chi_square,
3020
+ exclude=exclude,
3021
+ execution_hint=execution_hint,
3022
+ field=field,
3023
+ gnd=gnd,
3024
+ include=include,
3025
+ jlh=jlh,
3026
+ min_doc_count=min_doc_count,
3027
+ mutual_information=mutual_information,
3028
+ percentage=percentage,
3029
+ script_heuristic=script_heuristic,
3030
+ shard_min_doc_count=shard_min_doc_count,
3031
+ shard_size=shard_size,
3032
+ size=size,
3033
+ **kwargs,
3034
+ )
3035
+
3036
+
3037
+ class SignificantText(Bucket[_R]):
3038
+ """
3039
+ Returns interesting or unusual occurrences of free-text terms in a
3040
+ set.
3041
+
3042
+ :arg background_filter: A background filter that can be used to focus
3043
+ in on significant terms within a narrower context, instead of the
3044
+ entire index.
3045
+ :arg chi_square: Use Chi square, as described in "Information
3046
+ Retrieval", Manning et al., Chapter 13.5.2, as the significance
3047
+ score.
3048
+ :arg exclude: Values to exclude.
3049
+ :arg execution_hint: Determines whether the aggregation will use field
3050
+ values directly or global ordinals.
3051
+ :arg field: The field from which to return significant text.
3052
+ :arg filter_duplicate_text: Whether to out duplicate text to deal with
3053
+ noisy data.
3054
+ :arg gnd: Use Google normalized distance as described in "The Google
3055
+ Similarity Distance", Cilibrasi and Vitanyi, 2007, as the
3056
+ significance score.
3057
+ :arg include: Values to include.
3058
+ :arg jlh: Use JLH score as the significance score.
3059
+ :arg min_doc_count: Only return values that are found in more than
3060
+ `min_doc_count` hits. Defaults to `3` if omitted.
3061
+ :arg mutual_information: Use mutual information as described in
3062
+ "Information Retrieval", Manning et al., Chapter 13.5.1, as the
3063
+ significance score.
3064
+ :arg percentage: A simple calculation of the number of documents in
3065
+ the foreground sample with a term divided by the number of
3066
+ documents in the background with the term.
3067
+ :arg script_heuristic: Customized score, implemented via a script.
3068
+ :arg shard_min_doc_count: Regulates the certainty a shard has if the
3069
+ values should actually be added to the candidate list or not with
3070
+ respect to the min_doc_count. Values will only be considered if
3071
+ their local shard frequency within the set is higher than the
3072
+ `shard_min_doc_count`.
3073
+ :arg shard_size: The number of candidate terms produced by each shard.
3074
+ By default, `shard_size` will be automatically estimated based on
3075
+ the number of shards and the `size` parameter.
3076
+ :arg size: The number of buckets returned out of the overall terms
3077
+ list.
3078
+ :arg source_fields: Overrides the JSON `_source` fields from which
3079
+ text will be analyzed.
3080
+ """
3081
+
3082
+ name = "significant_text"
3083
+ _param_defs = {
3084
+ "background_filter": {"type": "query"},
3085
+ }
3086
+
3087
+ def __init__(
3088
+ self,
3089
+ *,
3090
+ background_filter: Union[Query, "DefaultType"] = DEFAULT,
3091
+ chi_square: Union[
3092
+ "types.ChiSquareHeuristic", Dict[str, Any], "DefaultType"
3093
+ ] = DEFAULT,
3094
+ exclude: Union[str, Sequence[str], "DefaultType"] = DEFAULT,
3095
+ execution_hint: Union[
3096
+ Literal[
3097
+ "map",
3098
+ "global_ordinals",
3099
+ "global_ordinals_hash",
3100
+ "global_ordinals_low_cardinality",
3101
+ ],
3102
+ "DefaultType",
3103
+ ] = DEFAULT,
3104
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
3105
+ filter_duplicate_text: Union[bool, "DefaultType"] = DEFAULT,
3106
+ gnd: Union[
3107
+ "types.GoogleNormalizedDistanceHeuristic", Dict[str, Any], "DefaultType"
3108
+ ] = DEFAULT,
3109
+ include: Union[
3110
+ str, Sequence[str], "types.TermsPartition", Dict[str, Any], "DefaultType"
3111
+ ] = DEFAULT,
3112
+ jlh: Union["types.EmptyObject", Dict[str, Any], "DefaultType"] = DEFAULT,
3113
+ min_doc_count: Union[int, "DefaultType"] = DEFAULT,
3114
+ mutual_information: Union[
3115
+ "types.MutualInformationHeuristic", Dict[str, Any], "DefaultType"
3116
+ ] = DEFAULT,
3117
+ percentage: Union[
3118
+ "types.PercentageScoreHeuristic", Dict[str, Any], "DefaultType"
3119
+ ] = DEFAULT,
3120
+ script_heuristic: Union[
3121
+ "types.ScriptedHeuristic", Dict[str, Any], "DefaultType"
3122
+ ] = DEFAULT,
3123
+ shard_min_doc_count: Union[int, "DefaultType"] = DEFAULT,
3124
+ shard_size: Union[int, "DefaultType"] = DEFAULT,
3125
+ size: Union[int, "DefaultType"] = DEFAULT,
3126
+ source_fields: Union[
3127
+ Union[str, "InstrumentedField"],
3128
+ Sequence[Union[str, "InstrumentedField"]],
3129
+ "DefaultType",
3130
+ ] = DEFAULT,
3131
+ **kwargs: Any,
3132
+ ):
3133
+ super().__init__(
3134
+ background_filter=background_filter,
3135
+ chi_square=chi_square,
3136
+ exclude=exclude,
3137
+ execution_hint=execution_hint,
3138
+ field=field,
3139
+ filter_duplicate_text=filter_duplicate_text,
3140
+ gnd=gnd,
3141
+ include=include,
3142
+ jlh=jlh,
3143
+ min_doc_count=min_doc_count,
3144
+ mutual_information=mutual_information,
3145
+ percentage=percentage,
3146
+ script_heuristic=script_heuristic,
3147
+ shard_min_doc_count=shard_min_doc_count,
3148
+ shard_size=shard_size,
3149
+ size=size,
3150
+ source_fields=source_fields,
3151
+ **kwargs,
3152
+ )
3153
+
3154
+
3155
+ class Stats(Agg[_R]):
3156
+ """
3157
+ A multi-value metrics aggregation that computes stats over numeric
3158
+ values extracted from the aggregated documents.
3159
+
3160
+ :arg format:
3161
+ :arg field: The field on which to run the aggregation.
3162
+ :arg missing: The value to apply to documents that do not have a
3163
+ value. By default, documents without a value are ignored.
3164
+ :arg script:
3165
+ """
3166
+
3167
+ name = "stats"
3168
+
3169
+ def __init__(
3170
+ self,
3171
+ *,
3172
+ format: Union[str, "DefaultType"] = DEFAULT,
3173
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
3174
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
3175
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
3176
+ **kwargs: Any,
3177
+ ):
3178
+ super().__init__(
3179
+ format=format, field=field, missing=missing, script=script, **kwargs
3180
+ )
3181
+
3182
+
3183
+ class StatsBucket(Pipeline[_R]):
3184
+ """
3185
+ A sibling pipeline aggregation which calculates a variety of stats
3186
+ across all bucket of a specified metric in a sibling aggregation.
3187
+
3188
+ :arg format: `DecimalFormat` pattern for the output value. If
3189
+ specified, the formatted value is returned in the aggregation’s
3190
+ `value_as_string` property.
3191
+ :arg gap_policy: Policy to apply when gaps are found in the data.
3192
+ Defaults to `skip` if omitted.
3193
+ :arg buckets_path: Path to the buckets that contain one set of values
3194
+ to correlate.
3195
+ """
3196
+
3197
+ name = "stats_bucket"
3198
+
3199
+ def __init__(
3200
+ self,
3201
+ *,
3202
+ format: Union[str, "DefaultType"] = DEFAULT,
3203
+ gap_policy: Union[
3204
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
3205
+ ] = DEFAULT,
3206
+ buckets_path: Union[
3207
+ str, Sequence[str], Mapping[str, str], "DefaultType"
3208
+ ] = DEFAULT,
3209
+ **kwargs: Any,
3210
+ ):
3211
+ super().__init__(
3212
+ format=format, gap_policy=gap_policy, buckets_path=buckets_path, **kwargs
3213
+ )
3214
+
3215
+
3216
+ class StringStats(Agg[_R]):
3217
+ """
3218
+ A multi-value metrics aggregation that computes statistics over string
3219
+ values extracted from the aggregated documents.
3220
+
3221
+ :arg show_distribution: Shows the probability distribution for all
3222
+ characters.
3223
+ :arg field: The field on which to run the aggregation.
3224
+ :arg missing: The value to apply to documents that do not have a
3225
+ value. By default, documents without a value are ignored.
3226
+ :arg script:
3227
+ """
3228
+
3229
+ name = "string_stats"
3230
+
3231
+ def __init__(
3232
+ self,
3233
+ *,
3234
+ show_distribution: Union[bool, "DefaultType"] = DEFAULT,
3235
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
3236
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
3237
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
3238
+ **kwargs: Any,
3239
+ ):
3240
+ super().__init__(
3241
+ show_distribution=show_distribution,
3242
+ field=field,
3243
+ missing=missing,
3244
+ script=script,
3245
+ **kwargs,
3246
+ )
3247
+
3248
+
3249
+ class Sum(Agg[_R]):
3250
+ """
3251
+ A single-value metrics aggregation that sums numeric values that are
3252
+ extracted from the aggregated documents.
3253
+
3254
+ :arg format:
3255
+ :arg field: The field on which to run the aggregation.
3256
+ :arg missing: The value to apply to documents that do not have a
3257
+ value. By default, documents without a value are ignored.
3258
+ :arg script:
3259
+ """
3260
+
3261
+ name = "sum"
3262
+
3263
+ def __init__(
3264
+ self,
3265
+ *,
3266
+ format: Union[str, "DefaultType"] = DEFAULT,
3267
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
3268
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
3269
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
3270
+ **kwargs: Any,
3271
+ ):
3272
+ super().__init__(
3273
+ format=format, field=field, missing=missing, script=script, **kwargs
3274
+ )
3275
+
3276
+
3277
+ class SumBucket(Pipeline[_R]):
3278
+ """
3279
+ A sibling pipeline aggregation which calculates the sum of a specified
3280
+ metric across all buckets in a sibling aggregation.
3281
+
3282
+ :arg format: `DecimalFormat` pattern for the output value. If
3283
+ specified, the formatted value is returned in the aggregation’s
3284
+ `value_as_string` property.
3285
+ :arg gap_policy: Policy to apply when gaps are found in the data.
3286
+ Defaults to `skip` if omitted.
3287
+ :arg buckets_path: Path to the buckets that contain one set of values
3288
+ to correlate.
3289
+ """
3290
+
3291
+ name = "sum_bucket"
3292
+
3293
+ def __init__(
3294
+ self,
3295
+ *,
3296
+ format: Union[str, "DefaultType"] = DEFAULT,
3297
+ gap_policy: Union[
3298
+ Literal["skip", "insert_zeros", "keep_values"], "DefaultType"
3299
+ ] = DEFAULT,
3300
+ buckets_path: Union[
3301
+ str, Sequence[str], Mapping[str, str], "DefaultType"
3302
+ ] = DEFAULT,
3303
+ **kwargs: Any,
3304
+ ):
3305
+ super().__init__(
3306
+ format=format, gap_policy=gap_policy, buckets_path=buckets_path, **kwargs
3307
+ )
3308
+
3309
+
3310
+ class Terms(Bucket[_R]):
3311
+ """
3312
+ A multi-bucket value source based aggregation where buckets are
3313
+ dynamically built - one per unique value.
3314
+
3315
+ :arg collect_mode: Determines how child aggregations should be
3316
+ calculated: breadth-first or depth-first.
3317
+ :arg exclude: Values to exclude. Accepts regular expressions and
3318
+ partitions.
3319
+ :arg execution_hint: Determines whether the aggregation will use field
3320
+ values directly or global ordinals.
3321
+ :arg field: The field from which to return terms.
3322
+ :arg include: Values to include. Accepts regular expressions and
3323
+ partitions.
3324
+ :arg min_doc_count: Only return values that are found in more than
3325
+ `min_doc_count` hits. Defaults to `1` if omitted.
3326
+ :arg missing: The value to apply to documents that do not have a
3327
+ value. By default, documents without a value are ignored.
3328
+ :arg missing_order:
3329
+ :arg missing_bucket:
3330
+ :arg value_type: Coerced unmapped fields into the specified type.
3331
+ :arg order: Specifies the sort order of the buckets. Defaults to
3332
+ sorting by descending document count.
3333
+ :arg script:
3334
+ :arg shard_min_doc_count: Regulates the certainty a shard has if the
3335
+ term should actually be added to the candidate list or not with
3336
+ respect to the `min_doc_count`. Terms will only be considered if
3337
+ their local shard frequency within the set is higher than the
3338
+ `shard_min_doc_count`.
3339
+ :arg shard_size: The number of candidate terms produced by each shard.
3340
+ By default, `shard_size` will be automatically estimated based on
3341
+ the number of shards and the `size` parameter.
3342
+ :arg show_term_doc_count_error: Set to `true` to return the
3343
+ `doc_count_error_upper_bound`, which is an upper bound to the
3344
+ error on the `doc_count` returned by each shard.
3345
+ :arg size: The number of buckets returned out of the overall terms
3346
+ list. Defaults to `10` if omitted.
3347
+ :arg format:
3348
+ """
3349
+
3350
+ name = "terms"
3351
+
3352
+ def __init__(
3353
+ self,
3354
+ *,
3355
+ collect_mode: Union[
3356
+ Literal["depth_first", "breadth_first"], "DefaultType"
3357
+ ] = DEFAULT,
3358
+ exclude: Union[str, Sequence[str], "DefaultType"] = DEFAULT,
3359
+ execution_hint: Union[
3360
+ Literal[
3361
+ "map",
3362
+ "global_ordinals",
3363
+ "global_ordinals_hash",
3364
+ "global_ordinals_low_cardinality",
3365
+ ],
3366
+ "DefaultType",
3367
+ ] = DEFAULT,
3368
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
3369
+ include: Union[
3370
+ str, Sequence[str], "types.TermsPartition", Dict[str, Any], "DefaultType"
3371
+ ] = DEFAULT,
3372
+ min_doc_count: Union[int, "DefaultType"] = DEFAULT,
3373
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
3374
+ missing_order: Union[
3375
+ Literal["first", "last", "default"], "DefaultType"
3376
+ ] = DEFAULT,
3377
+ missing_bucket: Union[bool, "DefaultType"] = DEFAULT,
3378
+ value_type: Union[str, "DefaultType"] = DEFAULT,
3379
+ order: Union[
3380
+ Mapping[Union[str, "InstrumentedField"], Literal["asc", "desc"]],
3381
+ Sequence[Mapping[Union[str, "InstrumentedField"], Literal["asc", "desc"]]],
3382
+ "DefaultType",
3383
+ ] = DEFAULT,
3384
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
3385
+ shard_min_doc_count: Union[int, "DefaultType"] = DEFAULT,
3386
+ shard_size: Union[int, "DefaultType"] = DEFAULT,
3387
+ show_term_doc_count_error: Union[bool, "DefaultType"] = DEFAULT,
3388
+ size: Union[int, "DefaultType"] = DEFAULT,
3389
+ format: Union[str, "DefaultType"] = DEFAULT,
3390
+ **kwargs: Any,
3391
+ ):
3392
+ super().__init__(
3393
+ collect_mode=collect_mode,
3394
+ exclude=exclude,
3395
+ execution_hint=execution_hint,
3396
+ field=field,
3397
+ include=include,
3398
+ min_doc_count=min_doc_count,
3399
+ missing=missing,
3400
+ missing_order=missing_order,
3401
+ missing_bucket=missing_bucket,
3402
+ value_type=value_type,
3403
+ order=order,
3404
+ script=script,
3405
+ shard_min_doc_count=shard_min_doc_count,
3406
+ shard_size=shard_size,
3407
+ show_term_doc_count_error=show_term_doc_count_error,
3408
+ size=size,
3409
+ format=format,
3410
+ **kwargs,
3411
+ )
3412
+
3413
+ def result(self, search: "SearchBase[_R]", data: Any) -> AttrDict[Any]:
3414
+ return FieldBucketData(self, search, data)
3415
+
3416
+
3417
+ class TimeSeries(Bucket[_R]):
3418
+ """
3419
+ The time series aggregation queries data created using a time series
3420
+ index. This is typically data such as metrics or other data streams
3421
+ with a time component, and requires creating an index using the time
3422
+ series mode.
3423
+
3424
+ :arg size: The maximum number of results to return. Defaults to
3425
+ `10000` if omitted.
3426
+ :arg keyed: Set to `true` to associate a unique string key with each
3427
+ bucket and returns the ranges as a hash rather than an array.
3428
+ """
3429
+
3430
+ name = "time_series"
3431
+
3432
+ def __init__(
3433
+ self,
3434
+ *,
3435
+ size: Union[int, "DefaultType"] = DEFAULT,
3436
+ keyed: Union[bool, "DefaultType"] = DEFAULT,
3437
+ **kwargs: Any,
3438
+ ):
3439
+ super().__init__(size=size, keyed=keyed, **kwargs)
3440
+
3441
+
3442
+ class TopHits(Agg[_R]):
3443
+ """
3444
+ A metric aggregation that returns the top matching documents per
3445
+ bucket.
3446
+
3447
+ :arg docvalue_fields: Fields for which to return doc values.
3448
+ :arg explain: If `true`, returns detailed information about score
3449
+ computation as part of a hit.
3450
+ :arg fields: Array of wildcard (*) patterns. The request returns
3451
+ values for field names matching these patterns in the hits.fields
3452
+ property of the response.
3453
+ :arg from: Starting document offset.
3454
+ :arg highlight: Specifies the highlighter to use for retrieving
3455
+ highlighted snippets from one or more fields in the search
3456
+ results.
3457
+ :arg script_fields: Returns the result of one or more script
3458
+ evaluations for each hit.
3459
+ :arg size: The maximum number of top matching hits to return per
3460
+ bucket. Defaults to `3` if omitted.
3461
+ :arg sort: Sort order of the top matching hits. By default, the hits
3462
+ are sorted by the score of the main query.
3463
+ :arg _source: Selects the fields of the source that are returned.
3464
+ :arg stored_fields: Returns values for the specified stored fields
3465
+ (fields that use the `store` mapping option).
3466
+ :arg track_scores: If `true`, calculates and returns document scores,
3467
+ even if the scores are not used for sorting.
3468
+ :arg version: If `true`, returns document version as part of a hit.
3469
+ :arg seq_no_primary_term: If `true`, returns sequence number and
3470
+ primary term of the last modification of each hit.
3471
+ :arg field: The field on which to run the aggregation.
3472
+ :arg missing: The value to apply to documents that do not have a
3473
+ value. By default, documents without a value are ignored.
3474
+ :arg script:
3475
+ """
3476
+
3477
+ name = "top_hits"
3478
+
3479
+ def __init__(
3480
+ self,
3481
+ *,
3482
+ docvalue_fields: Union[
3483
+ Sequence["types.FieldAndFormat"], Sequence[Dict[str, Any]], "DefaultType"
3484
+ ] = DEFAULT,
3485
+ explain: Union[bool, "DefaultType"] = DEFAULT,
3486
+ fields: Union[
3487
+ Sequence["types.FieldAndFormat"], Sequence[Dict[str, Any]], "DefaultType"
3488
+ ] = DEFAULT,
3489
+ from_: Union[int, "DefaultType"] = DEFAULT,
3490
+ highlight: Union["types.Highlight", Dict[str, Any], "DefaultType"] = DEFAULT,
3491
+ script_fields: Union[
3492
+ Mapping[str, "types.ScriptField"], Dict[str, Any], "DefaultType"
3493
+ ] = DEFAULT,
3494
+ size: Union[int, "DefaultType"] = DEFAULT,
3495
+ sort: Union[
3496
+ Union[Union[str, "InstrumentedField"], "types.SortOptions"],
3497
+ Sequence[Union[Union[str, "InstrumentedField"], "types.SortOptions"]],
3498
+ Dict[str, Any],
3499
+ "DefaultType",
3500
+ ] = DEFAULT,
3501
+ _source: Union[
3502
+ bool, "types.SourceFilter", Dict[str, Any], "DefaultType"
3503
+ ] = DEFAULT,
3504
+ stored_fields: Union[
3505
+ Union[str, "InstrumentedField"],
3506
+ Sequence[Union[str, "InstrumentedField"]],
3507
+ "DefaultType",
3508
+ ] = DEFAULT,
3509
+ track_scores: Union[bool, "DefaultType"] = DEFAULT,
3510
+ version: Union[bool, "DefaultType"] = DEFAULT,
3511
+ seq_no_primary_term: Union[bool, "DefaultType"] = DEFAULT,
3512
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
3513
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
3514
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
3515
+ **kwargs: Any,
3516
+ ):
3517
+ super().__init__(
3518
+ docvalue_fields=docvalue_fields,
3519
+ explain=explain,
3520
+ fields=fields,
3521
+ from_=from_,
3522
+ highlight=highlight,
3523
+ script_fields=script_fields,
3524
+ size=size,
3525
+ sort=sort,
3526
+ _source=_source,
3527
+ stored_fields=stored_fields,
3528
+ track_scores=track_scores,
3529
+ version=version,
3530
+ seq_no_primary_term=seq_no_primary_term,
3531
+ field=field,
3532
+ missing=missing,
3533
+ script=script,
3534
+ **kwargs,
3535
+ )
3536
+
3537
+ def result(self, search: "SearchBase[_R]", data: Any) -> AttrDict[Any]:
3538
+ return TopHitsData(self, search, data)
3539
+
3540
+
3541
+ class TTest(Agg[_R]):
3542
+ """
3543
+ A metrics aggregation that performs a statistical hypothesis test in
3544
+ which the test statistic follows a Student’s t-distribution under the
3545
+ null hypothesis on numeric values extracted from the aggregated
3546
+ documents.
3547
+
3548
+ :arg a: Test population A.
3549
+ :arg b: Test population B.
3550
+ :arg type: The type of test. Defaults to `heteroscedastic` if omitted.
3551
+ """
3552
+
3553
+ name = "t_test"
3554
+
3555
+ def __init__(
3556
+ self,
3557
+ *,
3558
+ a: Union["types.TestPopulation", Dict[str, Any], "DefaultType"] = DEFAULT,
3559
+ b: Union["types.TestPopulation", Dict[str, Any], "DefaultType"] = DEFAULT,
3560
+ type: Union[
3561
+ Literal["paired", "homoscedastic", "heteroscedastic"], "DefaultType"
3562
+ ] = DEFAULT,
3563
+ **kwargs: Any,
3564
+ ):
3565
+ super().__init__(a=a, b=b, type=type, **kwargs)
3566
+
3567
+
3568
+ class TopMetrics(Agg[_R]):
3569
+ """
3570
+ A metric aggregation that selects metrics from the document with the
3571
+ largest or smallest sort value.
3572
+
3573
+ :arg metrics: The fields of the top document to return.
3574
+ :arg size: The number of top documents from which to return metrics.
3575
+ Defaults to `1` if omitted.
3576
+ :arg sort: The sort order of the documents.
3577
+ :arg field: The field on which to run the aggregation.
3578
+ :arg missing: The value to apply to documents that do not have a
3579
+ value. By default, documents without a value are ignored.
3580
+ :arg script:
3581
+ """
3582
+
3583
+ name = "top_metrics"
3584
+
3585
+ def __init__(
3586
+ self,
3587
+ *,
3588
+ metrics: Union[
3589
+ "types.TopMetricsValue",
3590
+ Sequence["types.TopMetricsValue"],
3591
+ Sequence[Dict[str, Any]],
3592
+ "DefaultType",
3593
+ ] = DEFAULT,
3594
+ size: Union[int, "DefaultType"] = DEFAULT,
3595
+ sort: Union[
3596
+ Union[Union[str, "InstrumentedField"], "types.SortOptions"],
3597
+ Sequence[Union[Union[str, "InstrumentedField"], "types.SortOptions"]],
3598
+ Dict[str, Any],
3599
+ "DefaultType",
3600
+ ] = DEFAULT,
3601
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
3602
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
3603
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
3604
+ **kwargs: Any,
3605
+ ):
3606
+ super().__init__(
3607
+ metrics=metrics,
3608
+ size=size,
3609
+ sort=sort,
3610
+ field=field,
3611
+ missing=missing,
3612
+ script=script,
3613
+ **kwargs,
3614
+ )
3615
+
3616
+
3617
+ class ValueCount(Agg[_R]):
3618
+ """
3619
+ A single-value metrics aggregation that counts the number of values
3620
+ that are extracted from the aggregated documents.
3621
+
3622
+ :arg format:
3623
+ :arg field: The field on which to run the aggregation.
3624
+ :arg missing: The value to apply to documents that do not have a
3625
+ value. By default, documents without a value are ignored.
3626
+ :arg script:
3627
+ """
3628
+
3629
+ name = "value_count"
3630
+
3631
+ def __init__(
3632
+ self,
3633
+ *,
3634
+ format: Union[str, "DefaultType"] = DEFAULT,
3635
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
3636
+ missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
3637
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
3638
+ **kwargs: Any,
3639
+ ):
3640
+ super().__init__(
3641
+ format=format, field=field, missing=missing, script=script, **kwargs
3642
+ )
3643
+
3644
+
3645
+ class WeightedAvg(Agg[_R]):
3646
+ """
3647
+ A single-value metrics aggregation that computes the weighted average
3648
+ of numeric values that are extracted from the aggregated documents.
3649
+
3650
+ :arg format: A numeric response formatter.
3651
+ :arg value: Configuration for the field that provides the values.
3652
+ :arg value_type:
3653
+ :arg weight: Configuration for the field or script that provides the
3654
+ weights.
3655
+ """
3656
+
3657
+ name = "weighted_avg"
3658
+
3659
+ def __init__(
3660
+ self,
3661
+ *,
3662
+ format: Union[str, "DefaultType"] = DEFAULT,
3663
+ value: Union[
3664
+ "types.WeightedAverageValue", Dict[str, Any], "DefaultType"
3665
+ ] = DEFAULT,
3666
+ value_type: Union[
3667
+ Literal[
3668
+ "string",
3669
+ "long",
3670
+ "double",
3671
+ "number",
3672
+ "date",
3673
+ "date_nanos",
3674
+ "ip",
3675
+ "numeric",
3676
+ "geo_point",
3677
+ "boolean",
3678
+ ],
3679
+ "DefaultType",
3680
+ ] = DEFAULT,
3681
+ weight: Union[
3682
+ "types.WeightedAverageValue", Dict[str, Any], "DefaultType"
3683
+ ] = DEFAULT,
3684
+ **kwargs: Any,
3685
+ ):
3686
+ super().__init__(
3687
+ format=format, value=value, value_type=value_type, weight=weight, **kwargs
3688
+ )
3689
+
3690
+
3691
+ class VariableWidthHistogram(Bucket[_R]):
3692
+ """
3693
+ A multi-bucket aggregation similar to the histogram, except instead of
3694
+ providing an interval to use as the width of each bucket, a target
3695
+ number of buckets is provided.
3696
+
3697
+ :arg field: The name of the field.
3698
+ :arg buckets: The target number of buckets. Defaults to `10` if
3699
+ omitted.
3700
+ :arg shard_size: The number of buckets that the coordinating node will
3701
+ request from each shard. Defaults to `buckets * 50`.
3702
+ :arg initial_buffer: Specifies the number of individual documents that
3703
+ will be stored in memory on a shard before the initial bucketing
3704
+ algorithm is run. Defaults to `min(10 * shard_size, 50000)`.
3705
+ :arg script:
3706
+ """
3707
+
3708
+ name = "variable_width_histogram"
3709
+
3710
+ def __init__(
3711
+ self,
3712
+ *,
3713
+ field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
3714
+ buckets: Union[int, "DefaultType"] = DEFAULT,
3715
+ shard_size: Union[int, "DefaultType"] = DEFAULT,
3716
+ initial_buffer: Union[int, "DefaultType"] = DEFAULT,
3717
+ script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
3718
+ **kwargs: Any,
3719
+ ):
3720
+ super().__init__(
3721
+ field=field,
3722
+ buckets=buckets,
3723
+ shard_size=shard_size,
3724
+ initial_buffer=initial_buffer,
3725
+ script=script,
3726
+ **kwargs,
3727
+ )
3728
+
3729
+ def result(self, search: "SearchBase[_R]", data: Any) -> AttrDict[Any]:
3730
+ return FieldBucketData(self, search, data)