Skip to content

Commit a7084e4

Browse files
Handle new aggregation range types Pythoncally
1 parent 7ae3235 commit a7084e4

File tree

6 files changed

+6345
-412
lines changed

6 files changed

+6345
-412
lines changed

elasticsearch/dsl/aggs.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ def __init__(
761761
*,
762762
after: Union[
763763
Mapping[
764-
Union[str, "InstrumentedField"], Union[int, float, str, bool, None, Any]
764+
Union[str, "InstrumentedField"], Union[int, float, str, bool, None]
765765
],
766766
"DefaultType",
767767
] = DEFAULT,
@@ -958,7 +958,7 @@ def __init__(
958958
format: Union[str, "DefaultType"] = DEFAULT,
959959
missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
960960
ranges: Union[
961-
Sequence["types.DateRangeExpression"],
961+
Sequence["wrappers.AggregationRange"],
962962
Sequence[Dict[str, Any]],
963963
"DefaultType",
964964
] = DEFAULT,
@@ -1347,7 +1347,9 @@ def __init__(
13471347
"DefaultType",
13481348
] = DEFAULT,
13491349
ranges: Union[
1350-
Sequence["types.AggregationRange"], Sequence[Dict[str, Any]], "DefaultType"
1350+
Sequence["wrappers.AggregationRange"],
1351+
Sequence[Dict[str, Any]],
1352+
"DefaultType",
13511353
] = DEFAULT,
13521354
unit: Union[
13531355
Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "DefaultType"
@@ -2657,7 +2659,9 @@ def __init__(
26572659
field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
26582660
missing: Union[int, "DefaultType"] = DEFAULT,
26592661
ranges: Union[
2660-
Sequence["types.AggregationRange"], Sequence[Dict[str, Any]], "DefaultType"
2662+
Sequence["wrappers.AggregationRange"],
2663+
Sequence[Dict[str, Any]],
2664+
"DefaultType",
26612665
] = DEFAULT,
26622666
script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
26632667
keyed: Union[bool, "DefaultType"] = DEFAULT,

elasticsearch/dsl/field.py

Lines changed: 139 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,9 @@ def __init__(
437437
doc_class: Union[Type["InnerDoc"], "DefaultType"] = DEFAULT,
438438
*args: Any,
439439
enabled: Union[bool, "DefaultType"] = DEFAULT,
440-
subobjects: Union[bool, "DefaultType"] = DEFAULT,
440+
subobjects: Union[
441+
Literal["true", "false", "auto"], bool, "DefaultType"
442+
] = DEFAULT,
441443
copy_to: Union[
442444
Union[str, "InstrumentedField"],
443445
Sequence[Union[str, "InstrumentedField"]],
@@ -1092,6 +1094,56 @@ def __init__(
10921094
super().__init__(*args, **kwargs)
10931095

10941096

1097+
class CountedKeyword(Field):
1098+
"""
1099+
:arg index:
1100+
:arg meta: Metadata about the field.
1101+
:arg properties:
1102+
:arg ignore_above:
1103+
:arg dynamic:
1104+
:arg fields:
1105+
:arg synthetic_source_keep:
1106+
"""
1107+
1108+
name = "counted_keyword"
1109+
_param_defs = {
1110+
"properties": {"type": "field", "hash": True},
1111+
"fields": {"type": "field", "hash": True},
1112+
}
1113+
1114+
def __init__(
1115+
self,
1116+
*args: Any,
1117+
index: Union[bool, "DefaultType"] = DEFAULT,
1118+
meta: Union[Mapping[str, str], "DefaultType"] = DEFAULT,
1119+
properties: Union[Mapping[str, Field], "DefaultType"] = DEFAULT,
1120+
ignore_above: Union[int, "DefaultType"] = DEFAULT,
1121+
dynamic: Union[
1122+
Literal["strict", "runtime", "true", "false"], bool, "DefaultType"
1123+
] = DEFAULT,
1124+
fields: Union[Mapping[str, Field], "DefaultType"] = DEFAULT,
1125+
synthetic_source_keep: Union[
1126+
Literal["none", "arrays", "all"], "DefaultType"
1127+
] = DEFAULT,
1128+
**kwargs: Any,
1129+
):
1130+
if index is not DEFAULT:
1131+
kwargs["index"] = index
1132+
if meta is not DEFAULT:
1133+
kwargs["meta"] = meta
1134+
if properties is not DEFAULT:
1135+
kwargs["properties"] = properties
1136+
if ignore_above is not DEFAULT:
1137+
kwargs["ignore_above"] = ignore_above
1138+
if dynamic is not DEFAULT:
1139+
kwargs["dynamic"] = dynamic
1140+
if fields is not DEFAULT:
1141+
kwargs["fields"] = fields
1142+
if synthetic_source_keep is not DEFAULT:
1143+
kwargs["synthetic_source_keep"] = synthetic_source_keep
1144+
super().__init__(*args, **kwargs)
1145+
1146+
10951147
class Date(Field):
10961148
"""
10971149
:arg default_timezone: timezone that will be automatically used for tz-naive values
@@ -1101,6 +1153,8 @@ class Date(Field):
11011153
:arg format:
11021154
:arg ignore_malformed:
11031155
:arg index:
1156+
:arg script:
1157+
:arg on_script_error:
11041158
:arg null_value:
11051159
:arg precision_step:
11061160
:arg locale:
@@ -1133,6 +1187,8 @@ def __init__(
11331187
format: Union[str, "DefaultType"] = DEFAULT,
11341188
ignore_malformed: Union[bool, "DefaultType"] = DEFAULT,
11351189
index: Union[bool, "DefaultType"] = DEFAULT,
1190+
script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
1191+
on_script_error: Union[Literal["fail", "continue"], "DefaultType"] = DEFAULT,
11361192
null_value: Any = DEFAULT,
11371193
precision_step: Union[int, "DefaultType"] = DEFAULT,
11381194
locale: Union[str, "DefaultType"] = DEFAULT,
@@ -1165,6 +1221,10 @@ def __init__(
11651221
kwargs["ignore_malformed"] = ignore_malformed
11661222
if index is not DEFAULT:
11671223
kwargs["index"] = index
1224+
if script is not DEFAULT:
1225+
kwargs["script"] = script
1226+
if on_script_error is not DEFAULT:
1227+
kwargs["on_script_error"] = on_script_error
11681228
if null_value is not DEFAULT:
11691229
kwargs["null_value"] = null_value
11701230
if precision_step is not DEFAULT:
@@ -1229,6 +1289,8 @@ class DateNanos(Field):
12291289
:arg format:
12301290
:arg ignore_malformed:
12311291
:arg index:
1292+
:arg script:
1293+
:arg on_script_error:
12321294
:arg null_value:
12331295
:arg precision_step:
12341296
:arg doc_values:
@@ -1255,6 +1317,8 @@ def __init__(
12551317
format: Union[str, "DefaultType"] = DEFAULT,
12561318
ignore_malformed: Union[bool, "DefaultType"] = DEFAULT,
12571319
index: Union[bool, "DefaultType"] = DEFAULT,
1320+
script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
1321+
on_script_error: Union[Literal["fail", "continue"], "DefaultType"] = DEFAULT,
12581322
null_value: Any = DEFAULT,
12591323
precision_step: Union[int, "DefaultType"] = DEFAULT,
12601324
doc_values: Union[bool, "DefaultType"] = DEFAULT,
@@ -1284,6 +1348,10 @@ def __init__(
12841348
kwargs["ignore_malformed"] = ignore_malformed
12851349
if index is not DEFAULT:
12861350
kwargs["index"] = index
1351+
if script is not DEFAULT:
1352+
kwargs["script"] = script
1353+
if on_script_error is not DEFAULT:
1354+
kwargs["on_script_error"] = on_script_error
12871355
if null_value is not DEFAULT:
12881356
kwargs["null_value"] = null_value
12891357
if precision_step is not DEFAULT:
@@ -3068,6 +3136,76 @@ def __init__(
30683136
super().__init__(*args, **kwargs)
30693137

30703138

3139+
class Passthrough(Field):
3140+
"""
3141+
:arg enabled:
3142+
:arg priority:
3143+
:arg time_series_dimension:
3144+
:arg copy_to:
3145+
:arg store:
3146+
:arg meta: Metadata about the field.
3147+
:arg properties:
3148+
:arg ignore_above:
3149+
:arg dynamic:
3150+
:arg fields:
3151+
:arg synthetic_source_keep:
3152+
"""
3153+
3154+
name = "passthrough"
3155+
_param_defs = {
3156+
"properties": {"type": "field", "hash": True},
3157+
"fields": {"type": "field", "hash": True},
3158+
}
3159+
3160+
def __init__(
3161+
self,
3162+
*args: Any,
3163+
enabled: Union[bool, "DefaultType"] = DEFAULT,
3164+
priority: Union[int, "DefaultType"] = DEFAULT,
3165+
time_series_dimension: Union[bool, "DefaultType"] = DEFAULT,
3166+
copy_to: Union[
3167+
Union[str, "InstrumentedField"],
3168+
Sequence[Union[str, "InstrumentedField"]],
3169+
"DefaultType",
3170+
] = DEFAULT,
3171+
store: Union[bool, "DefaultType"] = DEFAULT,
3172+
meta: Union[Mapping[str, str], "DefaultType"] = DEFAULT,
3173+
properties: Union[Mapping[str, Field], "DefaultType"] = DEFAULT,
3174+
ignore_above: Union[int, "DefaultType"] = DEFAULT,
3175+
dynamic: Union[
3176+
Literal["strict", "runtime", "true", "false"], bool, "DefaultType"
3177+
] = DEFAULT,
3178+
fields: Union[Mapping[str, Field], "DefaultType"] = DEFAULT,
3179+
synthetic_source_keep: Union[
3180+
Literal["none", "arrays", "all"], "DefaultType"
3181+
] = DEFAULT,
3182+
**kwargs: Any,
3183+
):
3184+
if enabled is not DEFAULT:
3185+
kwargs["enabled"] = enabled
3186+
if priority is not DEFAULT:
3187+
kwargs["priority"] = priority
3188+
if time_series_dimension is not DEFAULT:
3189+
kwargs["time_series_dimension"] = time_series_dimension
3190+
if copy_to is not DEFAULT:
3191+
kwargs["copy_to"] = str(copy_to)
3192+
if store is not DEFAULT:
3193+
kwargs["store"] = store
3194+
if meta is not DEFAULT:
3195+
kwargs["meta"] = meta
3196+
if properties is not DEFAULT:
3197+
kwargs["properties"] = properties
3198+
if ignore_above is not DEFAULT:
3199+
kwargs["ignore_above"] = ignore_above
3200+
if dynamic is not DEFAULT:
3201+
kwargs["dynamic"] = dynamic
3202+
if fields is not DEFAULT:
3203+
kwargs["fields"] = fields
3204+
if synthetic_source_keep is not DEFAULT:
3205+
kwargs["synthetic_source_keep"] = synthetic_source_keep
3206+
super().__init__(*args, **kwargs)
3207+
3208+
30713209
class Percolator(Field):
30723210
"""
30733211
:arg meta: Metadata about the field.

elasticsearch/dsl/query.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,8 @@ class Knn(Query):
10831083
:arg filter: Filters for the kNN search query
10841084
:arg similarity: The minimum similarity for a vector to be considered
10851085
a match
1086+
:arg rescore_vector: Apply oversampling and rescoring to quantized
1087+
vectors *
10861088
:arg boost: Floating point number used to decrease or increase the
10871089
relevance scores of the query. Boost values are relative to the
10881090
default value of 1.0. A boost value between 0 and 1.0 decreases
@@ -1108,6 +1110,9 @@ def __init__(
11081110
k: Union[int, "DefaultType"] = DEFAULT,
11091111
filter: Union[Query, Sequence[Query], "DefaultType"] = DEFAULT,
11101112
similarity: Union[float, "DefaultType"] = DEFAULT,
1113+
rescore_vector: Union[
1114+
"types.RescoreVector", Dict[str, Any], "DefaultType"
1115+
] = DEFAULT,
11111116
boost: Union[float, "DefaultType"] = DEFAULT,
11121117
_name: Union[str, "DefaultType"] = DEFAULT,
11131118
**kwargs: Any,
@@ -1120,6 +1125,7 @@ def __init__(
11201125
k=k,
11211126
filter=filter,
11221127
similarity=similarity,
1128+
rescore_vector=rescore_vector,
11231129
boost=boost,
11241130
_name=_name,
11251131
**kwargs,
@@ -2650,7 +2656,7 @@ def __init__(
26502656
self,
26512657
_field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
26522658
_value: Union[
2653-
Sequence[Union[int, float, str, bool, None, Any]],
2659+
Sequence[Union[int, float, str, bool, None]],
26542660
"types.TermsLookup",
26552661
Dict[str, Any],
26562662
"DefaultType",

0 commit comments

Comments
 (0)