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