Skip to content

Commit d27658a

Browse files
authored
Merge branch 'main' into generates_main_code
2 parents 9235051 + b6d1211 commit d27658a

File tree

17 files changed

+277
-113
lines changed

17 files changed

+277
-113
lines changed

docs/reference/dsl_how_to_guides.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ s = Search(index='i').query(Match("title", "python"))
8484
response = s.delete()
8585
```
8686

87+
To pass [deletion parameters](https://elasticsearch-py.readthedocs.io/en/latest/api/elasticsearch.html#elasticsearch.Elasticsearch.delete_by_query)
88+
in your query, you can add them by calling ``params`` on the ``Search`` object before ``delete`` like this:
89+
90+
```python
91+
s = Search(index='i').query("match", title="python")
92+
s = s.params(ignore_unavailable=False, wait_for_completion=True)
93+
response = s.delete()
94+
```
95+
8796

8897
#### Queries [_queries]
8998

elasticsearch/_async/client/_base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ async def _perform_request(
272272
def mimetype_header_to_compat(header: str) -> None:
273273
# Converts all parts of a Accept/Content-Type headers
274274
# from application/X -> application/vnd.elasticsearch+X
275-
nonlocal request_headers
276275
mimetype = request_headers.get(header, None)
277276
if mimetype:
278277
request_headers[header] = _COMPAT_MIMETYPE_RE.sub(

elasticsearch/_async/helpers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ def aiter(x: Union[Iterable[T], AsyncIterable[T]]) -> AsyncIterator[T]:
136136
return x.__aiter__()
137137

138138
async def f() -> AsyncIterable[T]:
139-
nonlocal x
140139
ix: Iterable[T] = x
141140
for item in ix:
142141
yield item

elasticsearch/_sync/client/_base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ def _perform_request(
272272
def mimetype_header_to_compat(header: str) -> None:
273273
# Converts all parts of a Accept/Content-Type headers
274274
# from application/X -> application/vnd.elasticsearch+X
275-
nonlocal request_headers
276275
mimetype = request_headers.get(header, None)
277276
if mimetype:
278277
request_headers[header] = _COMPAT_MIMETYPE_RE.sub(

elasticsearch/_sync/client/utils.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ def client_node_configs(
124124

125125
def apply_node_options(node_config: NodeConfig) -> NodeConfig:
126126
"""Needs special handling of headers since .replace() wipes out existing headers"""
127-
nonlocal node_options
128127
headers = node_config.headers.copy() # type: ignore[attr-defined]
129128

130129
headers_to_add = node_options.pop("headers", ())
@@ -296,8 +295,6 @@ def _rewrite_parameters(
296295
def wrapper(api: F) -> F:
297296
@wraps(api)
298297
def wrapped(*args: Any, **kwargs: Any) -> Any:
299-
nonlocal api, body_name, body_fields
300-
301298
# Let's give a nicer error message when users pass positional arguments.
302299
if len(args) >= 2:
303300
raise TypeError(

elasticsearch/dsl/_async/search.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ async def scan(self) -> AsyncIterator[_R]:
107107
Turn the search into a scan search and return a generator that will
108108
iterate over all the documents matching the query.
109109
110-
Use ``params`` method to specify any additional arguments you with to
110+
Use the ``params`` method to specify any additional arguments you wish to
111111
pass to the underlying ``scan`` helper from ``elasticsearch-py`` -
112-
https://elasticsearch-py.readthedocs.io/en/master/helpers.html#elasticsearch.helpers.scan
112+
https://elasticsearch-py.readthedocs.io/en/latest/helpers.html#scan
113113
114114
The ``iterate()`` method should be preferred, as it provides similar
115115
functionality using an Elasticsearch point in time.
@@ -123,7 +123,11 @@ async def scan(self) -> AsyncIterator[_R]:
123123

124124
async def delete(self) -> AttrDict[Any]:
125125
"""
126-
delete() executes the query by delegating to delete_by_query()
126+
``delete()`` executes the query by delegating to ``delete_by_query()``.
127+
128+
Use the ``params`` method to specify any additional arguments you wish to
129+
pass to the underlying ``delete_by_query`` helper from ``elasticsearch-py`` -
130+
https://elasticsearch-py.readthedocs.io/en/latest/api/elasticsearch.html#elasticsearch.Elasticsearch.delete_by_query
127131
"""
128132

129133
es = get_connection(self._using)

elasticsearch/dsl/_sync/search.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ def scan(self) -> Iterator[_R]:
104104
Turn the search into a scan search and return a generator that will
105105
iterate over all the documents matching the query.
106106
107-
Use ``params`` method to specify any additional arguments you with to
107+
Use the ``params`` method to specify any additional arguments you wish to
108108
pass to the underlying ``scan`` helper from ``elasticsearch-py`` -
109-
https://elasticsearch-py.readthedocs.io/en/master/helpers.html#elasticsearch.helpers.scan
109+
https://elasticsearch-py.readthedocs.io/en/latest/helpers.html#scan
110110
111111
The ``iterate()`` method should be preferred, as it provides similar
112112
functionality using an Elasticsearch point in time.
@@ -118,7 +118,11 @@ def scan(self) -> Iterator[_R]:
118118

119119
def delete(self) -> AttrDict[Any]:
120120
"""
121-
delete() executes the query by delegating to delete_by_query()
121+
``delete()`` executes the query by delegating to ``delete_by_query()``.
122+
123+
Use the ``params`` method to specify any additional arguments you wish to
124+
pass to the underlying ``delete_by_query`` helper from ``elasticsearch-py`` -
125+
https://elasticsearch-py.readthedocs.io/en/latest/api/elasticsearch.html#elasticsearch.Elasticsearch.delete_by_query
122126
"""
123127

124128
es = get_connection(self._using)

elasticsearch/dsl/aggs.py

Lines changed: 9 additions & 4 deletions
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

Lines changed: 4 additions & 4 deletions
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

@@ -469,7 +469,7 @@ def params(self, **kwargs: Any) -> None:
469469
"""
470470
Specify query params to be used when executing the search. All the
471471
keyword arguments will override the current values. See
472-
https://elasticsearch-py.readthedocs.io/en/master/api.html#elasticsearch.Elasticsearch.search
472+
https://elasticsearch-py.readthedocs.io/en/latest/api/elasticsearch.html#elasticsearch.Elasticsearch.search
473473
for all available parameters.
474474
"""
475475
self._s = self._s.params(**kwargs)

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"]],
@@ -1109,6 +1111,56 @@ def __init__(
11091111
super().__init__(*args, **kwargs)
11101112

11111113

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+
11121164
class Date(Field):
11131165
"""
11141166
:arg default_timezone: timezone that will be automatically used for tz-naive values
@@ -1118,6 +1170,8 @@ class Date(Field):
11181170
:arg format:
11191171
:arg ignore_malformed:
11201172
:arg index:
1173+
:arg script:
1174+
:arg on_script_error:
11211175
:arg null_value:
11221176
:arg precision_step:
11231177
:arg locale:
@@ -1150,6 +1204,8 @@ def __init__(
11501204
format: Union[str, "DefaultType"] = DEFAULT,
11511205
ignore_malformed: Union[bool, "DefaultType"] = DEFAULT,
11521206
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,
11531209
null_value: Any = DEFAULT,
11541210
precision_step: Union[int, "DefaultType"] = DEFAULT,
11551211
locale: Union[str, "DefaultType"] = DEFAULT,
@@ -1182,6 +1238,10 @@ def __init__(
11821238
kwargs["ignore_malformed"] = ignore_malformed
11831239
if index is not DEFAULT:
11841240
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
11851245
if null_value is not DEFAULT:
11861246
kwargs["null_value"] = null_value
11871247
if precision_step is not DEFAULT:
@@ -1246,6 +1306,8 @@ class DateNanos(Field):
12461306
:arg format:
12471307
:arg ignore_malformed:
12481308
:arg index:
1309+
:arg script:
1310+
:arg on_script_error:
12491311
:arg null_value:
12501312
:arg precision_step:
12511313
:arg doc_values:
@@ -1272,6 +1334,8 @@ def __init__(
12721334
format: Union[str, "DefaultType"] = DEFAULT,
12731335
ignore_malformed: Union[bool, "DefaultType"] = DEFAULT,
12741336
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,
12751339
null_value: Any = DEFAULT,
12761340
precision_step: Union[int, "DefaultType"] = DEFAULT,
12771341
doc_values: Union[bool, "DefaultType"] = DEFAULT,
@@ -1301,6 +1365,10 @@ def __init__(
13011365
kwargs["ignore_malformed"] = ignore_malformed
13021366
if index is not DEFAULT:
13031367
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
13041372
if null_value is not DEFAULT:
13051373
kwargs["null_value"] = null_value
13061374
if precision_step is not DEFAULT:
@@ -3085,6 +3153,76 @@ def __init__(
30853153
super().__init__(*args, **kwargs)
30863154

30873155

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+
30883226
class Percolator(Field):
30893227
"""
30903228
:arg meta: Metadata about the field.

0 commit comments

Comments
 (0)