elasticsearch 9.0.2__py3-none-any.whl → 9.0.4__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.
- elasticsearch/_async/client/__init__.py +59 -202
- elasticsearch/_async/client/cat.py +1011 -59
- elasticsearch/_async/client/cluster.py +14 -4
- elasticsearch/_async/client/eql.py +10 -2
- elasticsearch/_async/client/esql.py +33 -10
- elasticsearch/_async/client/indices.py +88 -44
- elasticsearch/_async/client/inference.py +108 -3
- elasticsearch/_async/client/ingest.py +0 -7
- elasticsearch/_async/client/license.py +4 -4
- elasticsearch/_async/client/ml.py +6 -17
- elasticsearch/_async/client/monitoring.py +1 -1
- elasticsearch/_async/client/rollup.py +1 -22
- elasticsearch/_async/client/security.py +11 -17
- elasticsearch/_async/client/snapshot.py +6 -0
- elasticsearch/_async/client/sql.py +1 -1
- elasticsearch/_async/client/synonyms.py +1 -0
- elasticsearch/_async/client/transform.py +60 -0
- elasticsearch/_async/client/watcher.py +4 -2
- elasticsearch/_sync/client/__init__.py +59 -202
- elasticsearch/_sync/client/cat.py +1011 -59
- elasticsearch/_sync/client/cluster.py +14 -4
- elasticsearch/_sync/client/eql.py +10 -2
- elasticsearch/_sync/client/esql.py +33 -10
- elasticsearch/_sync/client/indices.py +88 -44
- elasticsearch/_sync/client/inference.py +108 -3
- elasticsearch/_sync/client/ingest.py +0 -7
- elasticsearch/_sync/client/license.py +4 -4
- elasticsearch/_sync/client/ml.py +6 -17
- elasticsearch/_sync/client/monitoring.py +1 -1
- elasticsearch/_sync/client/rollup.py +1 -22
- elasticsearch/_sync/client/security.py +11 -17
- elasticsearch/_sync/client/snapshot.py +6 -0
- elasticsearch/_sync/client/sql.py +1 -1
- elasticsearch/_sync/client/synonyms.py +1 -0
- elasticsearch/_sync/client/transform.py +60 -0
- elasticsearch/_sync/client/watcher.py +4 -2
- elasticsearch/_version.py +1 -1
- elasticsearch/compat.py +5 -0
- elasticsearch/dsl/__init__.py +2 -1
- elasticsearch/dsl/_async/document.py +84 -0
- elasticsearch/dsl/_sync/document.py +84 -0
- elasticsearch/dsl/document_base.py +219 -16
- elasticsearch/dsl/field.py +245 -57
- elasticsearch/dsl/query.py +7 -4
- elasticsearch/dsl/response/aggs.py +1 -1
- elasticsearch/dsl/types.py +125 -88
- elasticsearch/dsl/utils.py +2 -2
- elasticsearch/{dsl/_sync/_sync_check → esql}/__init__.py +3 -0
- elasticsearch/esql/esql.py +1156 -0
- elasticsearch/esql/functions.py +1750 -0
- {elasticsearch-9.0.2.dist-info → elasticsearch-9.0.4.dist-info}/METADATA +1 -3
- {elasticsearch-9.0.2.dist-info → elasticsearch-9.0.4.dist-info}/RECORD +55 -59
- elasticsearch/dsl/_sync/_sync_check/document.py +0 -514
- elasticsearch/dsl/_sync/_sync_check/faceted_search.py +0 -50
- elasticsearch/dsl/_sync/_sync_check/index.py +0 -597
- elasticsearch/dsl/_sync/_sync_check/mapping.py +0 -49
- elasticsearch/dsl/_sync/_sync_check/search.py +0 -230
- elasticsearch/dsl/_sync/_sync_check/update_by_query.py +0 -45
- {elasticsearch-9.0.2.dist-info → elasticsearch-9.0.4.dist-info}/WHEEL +0 -0
- {elasticsearch-9.0.2.dist-info → elasticsearch-9.0.4.dist-info}/licenses/LICENSE +0 -0
- {elasticsearch-9.0.2.dist-info → elasticsearch-9.0.4.dist-info}/licenses/NOTICE +0 -0
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
# specific language governing permissions and limitations
|
|
16
16
|
# under the License.
|
|
17
17
|
|
|
18
|
+
import json
|
|
18
19
|
from datetime import date, datetime
|
|
19
20
|
from fnmatch import fnmatch
|
|
20
21
|
from typing import (
|
|
@@ -27,6 +28,7 @@ from typing import (
|
|
|
27
28
|
List,
|
|
28
29
|
Optional,
|
|
29
30
|
Tuple,
|
|
31
|
+
Type,
|
|
30
32
|
TypeVar,
|
|
31
33
|
Union,
|
|
32
34
|
get_args,
|
|
@@ -48,6 +50,7 @@ from .utils import DOC_META_FIELDS, ObjectBase
|
|
|
48
50
|
if TYPE_CHECKING:
|
|
49
51
|
from elastic_transport import ObjectApiResponse
|
|
50
52
|
|
|
53
|
+
from ..esql.esql import ESQLBase
|
|
51
54
|
from .index_base import IndexBase
|
|
52
55
|
|
|
53
56
|
|
|
@@ -56,7 +59,163 @@ class MetaField:
|
|
|
56
59
|
self.args, self.kwargs = args, kwargs
|
|
57
60
|
|
|
58
61
|
|
|
59
|
-
class
|
|
62
|
+
class InstrumentedExpression:
|
|
63
|
+
"""Proxy object for a ES|QL expression."""
|
|
64
|
+
|
|
65
|
+
def __init__(self, expr: str):
|
|
66
|
+
self._expr = expr
|
|
67
|
+
|
|
68
|
+
def _render_value(self, value: Any) -> str:
|
|
69
|
+
if isinstance(value, InstrumentedExpression):
|
|
70
|
+
return str(value)
|
|
71
|
+
return json.dumps(value)
|
|
72
|
+
|
|
73
|
+
def __str__(self) -> str:
|
|
74
|
+
return self._expr
|
|
75
|
+
|
|
76
|
+
def __repr__(self) -> str:
|
|
77
|
+
return f"InstrumentedExpression[{self._expr}]"
|
|
78
|
+
|
|
79
|
+
def __pos__(self) -> "InstrumentedExpression":
|
|
80
|
+
return self
|
|
81
|
+
|
|
82
|
+
def __neg__(self) -> "InstrumentedExpression":
|
|
83
|
+
return InstrumentedExpression(f"-({self._expr})")
|
|
84
|
+
|
|
85
|
+
def __eq__(self, value: Any) -> "InstrumentedExpression": # type: ignore[override]
|
|
86
|
+
return InstrumentedExpression(f"{self._expr} == {self._render_value(value)}")
|
|
87
|
+
|
|
88
|
+
def __ne__(self, value: Any) -> "InstrumentedExpression": # type: ignore[override]
|
|
89
|
+
return InstrumentedExpression(f"{self._expr} != {self._render_value(value)}")
|
|
90
|
+
|
|
91
|
+
def __lt__(self, value: Any) -> "InstrumentedExpression":
|
|
92
|
+
return InstrumentedExpression(f"{self._expr} < {self._render_value(value)}")
|
|
93
|
+
|
|
94
|
+
def __gt__(self, value: Any) -> "InstrumentedExpression":
|
|
95
|
+
return InstrumentedExpression(f"{self._expr} > {self._render_value(value)}")
|
|
96
|
+
|
|
97
|
+
def __le__(self, value: Any) -> "InstrumentedExpression":
|
|
98
|
+
return InstrumentedExpression(f"{self._expr} <= {self._render_value(value)}")
|
|
99
|
+
|
|
100
|
+
def __ge__(self, value: Any) -> "InstrumentedExpression":
|
|
101
|
+
return InstrumentedExpression(f"{self._expr} >= {self._render_value(value)}")
|
|
102
|
+
|
|
103
|
+
def __add__(self, value: Any) -> "InstrumentedExpression":
|
|
104
|
+
return InstrumentedExpression(f"{self._expr} + {self._render_value(value)}")
|
|
105
|
+
|
|
106
|
+
def __radd__(self, value: Any) -> "InstrumentedExpression":
|
|
107
|
+
return InstrumentedExpression(f"{self._render_value(value)} + {self._expr}")
|
|
108
|
+
|
|
109
|
+
def __sub__(self, value: Any) -> "InstrumentedExpression":
|
|
110
|
+
return InstrumentedExpression(f"{self._expr} - {self._render_value(value)}")
|
|
111
|
+
|
|
112
|
+
def __rsub__(self, value: Any) -> "InstrumentedExpression":
|
|
113
|
+
return InstrumentedExpression(f"{self._render_value(value)} - {self._expr}")
|
|
114
|
+
|
|
115
|
+
def __mul__(self, value: Any) -> "InstrumentedExpression":
|
|
116
|
+
return InstrumentedExpression(f"{self._expr} * {self._render_value(value)}")
|
|
117
|
+
|
|
118
|
+
def __rmul__(self, value: Any) -> "InstrumentedExpression":
|
|
119
|
+
return InstrumentedExpression(f"{self._render_value(value)} * {self._expr}")
|
|
120
|
+
|
|
121
|
+
def __truediv__(self, value: Any) -> "InstrumentedExpression":
|
|
122
|
+
return InstrumentedExpression(f"{self._expr} / {self._render_value(value)}")
|
|
123
|
+
|
|
124
|
+
def __rtruediv__(self, value: Any) -> "InstrumentedExpression":
|
|
125
|
+
return InstrumentedExpression(f"{self._render_value(value)} / {self._expr}")
|
|
126
|
+
|
|
127
|
+
def __mod__(self, value: Any) -> "InstrumentedExpression":
|
|
128
|
+
return InstrumentedExpression(f"{self._expr} % {self._render_value(value)}")
|
|
129
|
+
|
|
130
|
+
def __rmod__(self, value: Any) -> "InstrumentedExpression":
|
|
131
|
+
return InstrumentedExpression(f"{self._render_value(value)} % {self._expr}")
|
|
132
|
+
|
|
133
|
+
def is_null(self) -> "InstrumentedExpression":
|
|
134
|
+
"""Compare the expression against NULL."""
|
|
135
|
+
return InstrumentedExpression(f"{self._expr} IS NULL")
|
|
136
|
+
|
|
137
|
+
def is_not_null(self) -> "InstrumentedExpression":
|
|
138
|
+
"""Compare the expression against NOT NULL."""
|
|
139
|
+
return InstrumentedExpression(f"{self._expr} IS NOT NULL")
|
|
140
|
+
|
|
141
|
+
def in_(self, *values: Any) -> "InstrumentedExpression":
|
|
142
|
+
"""Test if the expression equals one of the given values."""
|
|
143
|
+
rendered_values = ", ".join([f"{value}" for value in values])
|
|
144
|
+
return InstrumentedExpression(f"{self._expr} IN ({rendered_values})")
|
|
145
|
+
|
|
146
|
+
def like(self, *patterns: str) -> "InstrumentedExpression":
|
|
147
|
+
"""Filter the expression using a string pattern."""
|
|
148
|
+
if len(patterns) == 1:
|
|
149
|
+
return InstrumentedExpression(
|
|
150
|
+
f"{self._expr} LIKE {self._render_value(patterns[0])}"
|
|
151
|
+
)
|
|
152
|
+
else:
|
|
153
|
+
return InstrumentedExpression(
|
|
154
|
+
f'{self._expr} LIKE ({", ".join([self._render_value(p) for p in patterns])})'
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
def rlike(self, *patterns: str) -> "InstrumentedExpression":
|
|
158
|
+
"""Filter the expression using a regular expression."""
|
|
159
|
+
if len(patterns) == 1:
|
|
160
|
+
return InstrumentedExpression(
|
|
161
|
+
f"{self._expr} RLIKE {self._render_value(patterns[0])}"
|
|
162
|
+
)
|
|
163
|
+
else:
|
|
164
|
+
return InstrumentedExpression(
|
|
165
|
+
f'{self._expr} RLIKE ({", ".join([self._render_value(p) for p in patterns])})'
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
def match(self, query: str) -> "InstrumentedExpression":
|
|
169
|
+
"""Perform a match query on the field."""
|
|
170
|
+
return InstrumentedExpression(f"{self._expr}:{self._render_value(query)}")
|
|
171
|
+
|
|
172
|
+
def asc(self) -> "InstrumentedExpression":
|
|
173
|
+
"""Return the field name representation for ascending sort order.
|
|
174
|
+
|
|
175
|
+
For use in ES|QL queries only.
|
|
176
|
+
"""
|
|
177
|
+
return InstrumentedExpression(f"{self._expr} ASC")
|
|
178
|
+
|
|
179
|
+
def desc(self) -> "InstrumentedExpression":
|
|
180
|
+
"""Return the field name representation for descending sort order.
|
|
181
|
+
|
|
182
|
+
For use in ES|QL queries only.
|
|
183
|
+
"""
|
|
184
|
+
return InstrumentedExpression(f"{self._expr} DESC")
|
|
185
|
+
|
|
186
|
+
def nulls_first(self) -> "InstrumentedExpression":
|
|
187
|
+
"""Return the field name representation for nulls first sort order.
|
|
188
|
+
|
|
189
|
+
For use in ES|QL queries only.
|
|
190
|
+
"""
|
|
191
|
+
return InstrumentedExpression(f"{self._expr} NULLS FIRST")
|
|
192
|
+
|
|
193
|
+
def nulls_last(self) -> "InstrumentedExpression":
|
|
194
|
+
"""Return the field name representation for nulls last sort order.
|
|
195
|
+
|
|
196
|
+
For use in ES|QL queries only.
|
|
197
|
+
"""
|
|
198
|
+
return InstrumentedExpression(f"{self._expr} NULLS LAST")
|
|
199
|
+
|
|
200
|
+
def where(
|
|
201
|
+
self, *expressions: Union[str, "InstrumentedExpression"]
|
|
202
|
+
) -> "InstrumentedExpression":
|
|
203
|
+
"""Add a condition to be met for the row to be included.
|
|
204
|
+
|
|
205
|
+
Use only in expressions given in the ``STATS`` command.
|
|
206
|
+
"""
|
|
207
|
+
if len(expressions) == 1:
|
|
208
|
+
return InstrumentedExpression(f"{self._expr} WHERE {expressions[0]}")
|
|
209
|
+
else:
|
|
210
|
+
return InstrumentedExpression(
|
|
211
|
+
f'{self._expr} WHERE {" AND ".join([f"({expr})" for expr in expressions])}'
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
E = InstrumentedExpression
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
class InstrumentedField(InstrumentedExpression):
|
|
60
219
|
"""Proxy object for a mapped document field.
|
|
61
220
|
|
|
62
221
|
An object of this instance is returned when a field is accessed as a class
|
|
@@ -71,8 +230,8 @@ class InstrumentedField:
|
|
|
71
230
|
s = s.sort(-MyDocument.name) # sort by name in descending order
|
|
72
231
|
"""
|
|
73
232
|
|
|
74
|
-
def __init__(self, name: str, field: Field):
|
|
75
|
-
|
|
233
|
+
def __init__(self, name: str, field: Optional[Field]):
|
|
234
|
+
super().__init__(name)
|
|
76
235
|
self._field = field
|
|
77
236
|
|
|
78
237
|
# note that the return value type here assumes classes will only be used to
|
|
@@ -83,26 +242,29 @@ class InstrumentedField:
|
|
|
83
242
|
# first let's see if this is an attribute of this object
|
|
84
243
|
return super().__getattribute__(attr) # type: ignore[no-any-return]
|
|
85
244
|
except AttributeError:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
245
|
+
if self._field:
|
|
246
|
+
try:
|
|
247
|
+
# next we see if we have a sub-field with this name
|
|
248
|
+
return InstrumentedField(f"{self._expr}.{attr}", self._field[attr])
|
|
249
|
+
except KeyError:
|
|
250
|
+
# lastly we let the wrapped field resolve this attribute
|
|
251
|
+
return getattr(self._field, attr) # type: ignore[no-any-return]
|
|
252
|
+
else:
|
|
253
|
+
raise
|
|
254
|
+
|
|
255
|
+
def __pos__(self) -> str: # type: ignore[override]
|
|
94
256
|
"""Return the field name representation for ascending sort order"""
|
|
95
|
-
return f"{self.
|
|
257
|
+
return f"{self._expr}"
|
|
96
258
|
|
|
97
|
-
def __neg__(self) -> str:
|
|
259
|
+
def __neg__(self) -> str: # type: ignore[override]
|
|
98
260
|
"""Return the field name representation for descending sort order"""
|
|
99
|
-
return f"-{self.
|
|
261
|
+
return f"-{self._expr}"
|
|
100
262
|
|
|
101
263
|
def __str__(self) -> str:
|
|
102
|
-
return self.
|
|
264
|
+
return self._expr
|
|
103
265
|
|
|
104
266
|
def __repr__(self) -> str:
|
|
105
|
-
return f"InstrumentedField[{self.
|
|
267
|
+
return f"InstrumentedField[{self._expr}]"
|
|
106
268
|
|
|
107
269
|
|
|
108
270
|
class DocumentMeta(type):
|
|
@@ -442,3 +604,44 @@ class DocumentBase(ObjectBase):
|
|
|
442
604
|
|
|
443
605
|
meta["_source"] = d
|
|
444
606
|
return meta
|
|
607
|
+
|
|
608
|
+
@classmethod
|
|
609
|
+
def _get_field_names(
|
|
610
|
+
cls, for_esql: bool = False, nested_class: Optional[Type[InnerDoc]] = None
|
|
611
|
+
) -> List[str]:
|
|
612
|
+
"""Return the list of field names used by this document.
|
|
613
|
+
If the document has nested objects, their fields are reported using dot
|
|
614
|
+
notation. If the ``for_esql`` argument is set to ``True``, the list omits
|
|
615
|
+
nested fields, which are currently unsupported in ES|QL.
|
|
616
|
+
"""
|
|
617
|
+
fields = []
|
|
618
|
+
class_ = nested_class or cls
|
|
619
|
+
for field_name in class_._doc_type.mapping:
|
|
620
|
+
field = class_._doc_type.mapping[field_name]
|
|
621
|
+
if isinstance(field, Object):
|
|
622
|
+
if for_esql and isinstance(field, Nested):
|
|
623
|
+
# ES|QL does not recognize Nested fields at this time
|
|
624
|
+
continue
|
|
625
|
+
sub_fields = cls._get_field_names(
|
|
626
|
+
for_esql=for_esql, nested_class=field._doc_class
|
|
627
|
+
)
|
|
628
|
+
for sub_field in sub_fields:
|
|
629
|
+
fields.append(f"{field_name}.{sub_field}")
|
|
630
|
+
else:
|
|
631
|
+
fields.append(field_name)
|
|
632
|
+
return fields
|
|
633
|
+
|
|
634
|
+
@classmethod
|
|
635
|
+
def esql_from(cls) -> "ESQLBase":
|
|
636
|
+
"""Return a base ES|QL query for instances of this document class.
|
|
637
|
+
|
|
638
|
+
The returned query is initialized with ``FROM`` and ``KEEP`` statements,
|
|
639
|
+
and can be completed as desired.
|
|
640
|
+
"""
|
|
641
|
+
from ..esql import ESQL # here to avoid circular imports
|
|
642
|
+
|
|
643
|
+
return (
|
|
644
|
+
ESQL.from_(cls)
|
|
645
|
+
.metadata("_id")
|
|
646
|
+
.keep("_id", *tuple(cls._get_field_names(for_esql=True)))
|
|
647
|
+
)
|