Skip to content

Commit 43ce0dc

Browse files
Handle new aggregation range types Pythoncally (#2860) (#2865)
(cherry picked from commit a224f49) Co-authored-by: Miguel Grinberg <[email protected]>
1 parent 01893c8 commit 43ce0dc

File tree

8 files changed

+269
-96
lines changed

8 files changed

+269
-96
lines changed

elasticsearch/dsl/aggs.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
from elastic_transport.client_utils import DEFAULT
3737

38+
from . import wrappers
3839
from .query import Query
3940
from .response.aggs import AggResponse, BucketData, FieldBucketData, TopHitsData
4041
from .utils import _R, AttrDict, DslBase
@@ -761,7 +762,7 @@ def __init__(
761762
*,
762763
after: Union[
763764
Mapping[
764-
Union[str, "InstrumentedField"], Union[int, float, str, bool, None, Any]
765+
Union[str, "InstrumentedField"], Union[int, float, str, bool, None]
765766
],
766767
"DefaultType",
767768
] = DEFAULT,
@@ -958,7 +959,7 @@ def __init__(
958959
format: Union[str, "DefaultType"] = DEFAULT,
959960
missing: Union[str, int, float, bool, "DefaultType"] = DEFAULT,
960961
ranges: Union[
961-
Sequence["types.DateRangeExpression"],
962+
Sequence["wrappers.AggregationRange"],
962963
Sequence[Dict[str, Any]],
963964
"DefaultType",
964965
] = DEFAULT,
@@ -1347,7 +1348,9 @@ def __init__(
13471348
"DefaultType",
13481349
] = DEFAULT,
13491350
ranges: Union[
1350-
Sequence["types.AggregationRange"], Sequence[Dict[str, Any]], "DefaultType"
1351+
Sequence["wrappers.AggregationRange"],
1352+
Sequence[Dict[str, Any]],
1353+
"DefaultType",
13511354
] = DEFAULT,
13521355
unit: Union[
13531356
Literal["in", "ft", "yd", "mi", "nmi", "km", "m", "cm", "mm"], "DefaultType"
@@ -2657,7 +2660,9 @@ def __init__(
26572660
field: Union[str, "InstrumentedField", "DefaultType"] = DEFAULT,
26582661
missing: Union[int, "DefaultType"] = DEFAULT,
26592662
ranges: Union[
2660-
Sequence["types.AggregationRange"], Sequence[Dict[str, Any]], "DefaultType"
2663+
Sequence["wrappers.AggregationRange"],
2664+
Sequence[Dict[str, Any]],
2665+
"DefaultType",
26612666
] = DEFAULT,
26622667
script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
26632668
keyed: Union[bool, "DefaultType"] = DEFAULT,

elasticsearch/dsl/faceted_search_base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from .response.aggs import BucketData
4343
from .search_base import SearchBase
4444

45-
FilterValueType = Union[str, datetime, Sequence[str]]
45+
FilterValueType = Union[str, int, float, bool]
4646

4747
__all__ = [
4848
"FacetedSearchBase",
@@ -396,10 +396,10 @@ def add_filter(
396396
]
397397

398398
# remember the filter values for use in FacetedResponse
399-
self.filter_values[name] = filter_values # type: ignore[assignment]
399+
self.filter_values[name] = filter_values
400400

401401
# get the filter from the facet
402-
f = self.facets[name].add_filter(filter_values) # type: ignore[arg-type]
402+
f = self.facets[name].add_filter(filter_values)
403403
if f is None:
404404
return
405405

elasticsearch/dsl/field.py

+156-1
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"]],
@@ -762,6 +764,11 @@ class Boolean(Field):
762764
:arg fielddata:
763765
:arg index:
764766
:arg null_value:
767+
:arg ignore_malformed:
768+
:arg script:
769+
:arg on_script_error:
770+
:arg time_series_dimension: For internal use by Elastic only. Marks
771+
the field as a time series dimension. Defaults to false.
765772
:arg doc_values:
766773
:arg copy_to:
767774
:arg store:
@@ -789,6 +796,10 @@ def __init__(
789796
] = DEFAULT,
790797
index: Union[bool, "DefaultType"] = DEFAULT,
791798
null_value: Union[bool, "DefaultType"] = DEFAULT,
799+
ignore_malformed: Union[bool, "DefaultType"] = DEFAULT,
800+
script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
801+
on_script_error: Union[Literal["fail", "continue"], "DefaultType"] = DEFAULT,
802+
time_series_dimension: Union[bool, "DefaultType"] = DEFAULT,
792803
doc_values: Union[bool, "DefaultType"] = DEFAULT,
793804
copy_to: Union[
794805
Union[str, "InstrumentedField"],
@@ -816,6 +827,14 @@ def __init__(
816827
kwargs["index"] = index
817828
if null_value is not DEFAULT:
818829
kwargs["null_value"] = null_value
830+
if ignore_malformed is not DEFAULT:
831+
kwargs["ignore_malformed"] = ignore_malformed
832+
if script is not DEFAULT:
833+
kwargs["script"] = script
834+
if on_script_error is not DEFAULT:
835+
kwargs["on_script_error"] = on_script_error
836+
if time_series_dimension is not DEFAULT:
837+
kwargs["time_series_dimension"] = time_series_dimension
819838
if doc_values is not DEFAULT:
820839
kwargs["doc_values"] = doc_values
821840
if copy_to is not DEFAULT:
@@ -1092,6 +1111,56 @@ def __init__(
10921111
super().__init__(*args, **kwargs)
10931112

10941113

1114+
class CountedKeyword(Field):
1115+
"""
1116+
:arg index:
1117+
:arg meta: Metadata about the field.
1118+
:arg properties:
1119+
:arg ignore_above:
1120+
:arg dynamic:
1121+
:arg fields:
1122+
:arg synthetic_source_keep:
1123+
"""
1124+
1125+
name = "counted_keyword"
1126+
_param_defs = {
1127+
"properties": {"type": "field", "hash": True},
1128+
"fields": {"type": "field", "hash": True},
1129+
}
1130+
1131+
def __init__(
1132+
self,
1133+
*args: Any,
1134+
index: Union[bool, "DefaultType"] = DEFAULT,
1135+
meta: Union[Mapping[str, str], "DefaultType"] = DEFAULT,
1136+
properties: Union[Mapping[str, Field], "DefaultType"] = DEFAULT,
1137+
ignore_above: Union[int, "DefaultType"] = DEFAULT,
1138+
dynamic: Union[
1139+
Literal["strict", "runtime", "true", "false"], bool, "DefaultType"
1140+
] = DEFAULT,
1141+
fields: Union[Mapping[str, Field], "DefaultType"] = DEFAULT,
1142+
synthetic_source_keep: Union[
1143+
Literal["none", "arrays", "all"], "DefaultType"
1144+
] = DEFAULT,
1145+
**kwargs: Any,
1146+
):
1147+
if index is not DEFAULT:
1148+
kwargs["index"] = index
1149+
if meta is not DEFAULT:
1150+
kwargs["meta"] = meta
1151+
if properties is not DEFAULT:
1152+
kwargs["properties"] = properties
1153+
if ignore_above is not DEFAULT:
1154+
kwargs["ignore_above"] = ignore_above
1155+
if dynamic is not DEFAULT:
1156+
kwargs["dynamic"] = dynamic
1157+
if fields is not DEFAULT:
1158+
kwargs["fields"] = fields
1159+
if synthetic_source_keep is not DEFAULT:
1160+
kwargs["synthetic_source_keep"] = synthetic_source_keep
1161+
super().__init__(*args, **kwargs)
1162+
1163+
10951164
class Date(Field):
10961165
"""
10971166
:arg default_timezone: timezone that will be automatically used for tz-naive values
@@ -1101,6 +1170,8 @@ class Date(Field):
11011170
:arg format:
11021171
:arg ignore_malformed:
11031172
:arg index:
1173+
:arg script:
1174+
:arg on_script_error:
11041175
:arg null_value:
11051176
:arg precision_step:
11061177
:arg locale:
@@ -1133,6 +1204,8 @@ def __init__(
11331204
format: Union[str, "DefaultType"] = DEFAULT,
11341205
ignore_malformed: Union[bool, "DefaultType"] = DEFAULT,
11351206
index: Union[bool, "DefaultType"] = DEFAULT,
1207+
script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
1208+
on_script_error: Union[Literal["fail", "continue"], "DefaultType"] = DEFAULT,
11361209
null_value: Any = DEFAULT,
11371210
precision_step: Union[int, "DefaultType"] = DEFAULT,
11381211
locale: Union[str, "DefaultType"] = DEFAULT,
@@ -1165,6 +1238,10 @@ def __init__(
11651238
kwargs["ignore_malformed"] = ignore_malformed
11661239
if index is not DEFAULT:
11671240
kwargs["index"] = index
1241+
if script is not DEFAULT:
1242+
kwargs["script"] = script
1243+
if on_script_error is not DEFAULT:
1244+
kwargs["on_script_error"] = on_script_error
11681245
if null_value is not DEFAULT:
11691246
kwargs["null_value"] = null_value
11701247
if precision_step is not DEFAULT:
@@ -1229,6 +1306,8 @@ class DateNanos(Field):
12291306
:arg format:
12301307
:arg ignore_malformed:
12311308
:arg index:
1309+
:arg script:
1310+
:arg on_script_error:
12321311
:arg null_value:
12331312
:arg precision_step:
12341313
:arg doc_values:
@@ -1255,6 +1334,8 @@ def __init__(
12551334
format: Union[str, "DefaultType"] = DEFAULT,
12561335
ignore_malformed: Union[bool, "DefaultType"] = DEFAULT,
12571336
index: Union[bool, "DefaultType"] = DEFAULT,
1337+
script: Union["types.Script", Dict[str, Any], "DefaultType"] = DEFAULT,
1338+
on_script_error: Union[Literal["fail", "continue"], "DefaultType"] = DEFAULT,
12581339
null_value: Any = DEFAULT,
12591340
precision_step: Union[int, "DefaultType"] = DEFAULT,
12601341
doc_values: Union[bool, "DefaultType"] = DEFAULT,
@@ -1284,6 +1365,10 @@ def __init__(
12841365
kwargs["ignore_malformed"] = ignore_malformed
12851366
if index is not DEFAULT:
12861367
kwargs["index"] = index
1368+
if script is not DEFAULT:
1369+
kwargs["script"] = script
1370+
if on_script_error is not DEFAULT:
1371+
kwargs["on_script_error"] = on_script_error
12871372
if null_value is not DEFAULT:
12881373
kwargs["null_value"] = null_value
12891374
if precision_step is not DEFAULT:
@@ -3068,6 +3153,76 @@ def __init__(
30683153
super().__init__(*args, **kwargs)
30693154

30703155

3156+
class Passthrough(Field):
3157+
"""
3158+
:arg enabled:
3159+
:arg priority:
3160+
:arg time_series_dimension:
3161+
:arg copy_to:
3162+
:arg store:
3163+
:arg meta: Metadata about the field.
3164+
:arg properties:
3165+
:arg ignore_above:
3166+
:arg dynamic:
3167+
:arg fields:
3168+
:arg synthetic_source_keep:
3169+
"""
3170+
3171+
name = "passthrough"
3172+
_param_defs = {
3173+
"properties": {"type": "field", "hash": True},
3174+
"fields": {"type": "field", "hash": True},
3175+
}
3176+
3177+
def __init__(
3178+
self,
3179+
*args: Any,
3180+
enabled: Union[bool, "DefaultType"] = DEFAULT,
3181+
priority: Union[int, "DefaultType"] = DEFAULT,
3182+
time_series_dimension: Union[bool, "DefaultType"] = DEFAULT,
3183+
copy_to: Union[
3184+
Union[str, "InstrumentedField"],
3185+
Sequence[Union[str, "InstrumentedField"]],
3186+
"DefaultType",
3187+
] = DEFAULT,
3188+
store: Union[bool, "DefaultType"] = DEFAULT,
3189+
meta: Union[Mapping[str, str], "DefaultType"] = DEFAULT,
3190+
properties: Union[Mapping[str, Field], "DefaultType"] = DEFAULT,
3191+
ignore_above: Union[int, "DefaultType"] = DEFAULT,
3192+
dynamic: Union[
3193+
Literal["strict", "runtime", "true", "false"], bool, "DefaultType"
3194+
] = DEFAULT,
3195+
fields: Union[Mapping[str, Field], "DefaultType"] = DEFAULT,
3196+
synthetic_source_keep: Union[
3197+
Literal["none", "arrays", "all"], "DefaultType"
3198+
] = DEFAULT,
3199+
**kwargs: Any,
3200+
):
3201+
if enabled is not DEFAULT:
3202+
kwargs["enabled"] = enabled
3203+
if priority is not DEFAULT:
3204+
kwargs["priority"] = priority
3205+
if time_series_dimension is not DEFAULT:
3206+
kwargs["time_series_dimension"] = time_series_dimension
3207+
if copy_to is not DEFAULT:
3208+
kwargs["copy_to"] = str(copy_to)
3209+
if store is not DEFAULT:
3210+
kwargs["store"] = store
3211+
if meta is not DEFAULT:
3212+
kwargs["meta"] = meta
3213+
if properties is not DEFAULT:
3214+
kwargs["properties"] = properties
3215+
if ignore_above is not DEFAULT:
3216+
kwargs["ignore_above"] = ignore_above
3217+
if dynamic is not DEFAULT:
3218+
kwargs["dynamic"] = dynamic
3219+
if fields is not DEFAULT:
3220+
kwargs["fields"] = fields
3221+
if synthetic_source_keep is not DEFAULT:
3222+
kwargs["synthetic_source_keep"] = synthetic_source_keep
3223+
super().__init__(*args, **kwargs)
3224+
3225+
30713226
class Percolator(Field):
30723227
"""
30733228
:arg meta: Metadata about the field.

elasticsearch/dsl/query.py

+7-1
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)