elasticsearch 8.17.2__py3-none-any.whl → 8.18.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 (135) hide show
  1. elasticsearch/_async/client/__init__.py +174 -79
  2. elasticsearch/_async/client/_base.py +0 -1
  3. elasticsearch/_async/client/async_search.py +12 -8
  4. elasticsearch/_async/client/autoscaling.py +4 -4
  5. elasticsearch/_async/client/cat.py +26 -26
  6. elasticsearch/_async/client/ccr.py +186 -72
  7. elasticsearch/_async/client/cluster.py +38 -19
  8. elasticsearch/_async/client/connector.py +30 -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 +62 -6
  13. elasticsearch/_async/client/features.py +12 -2
  14. elasticsearch/_async/client/fleet.py +8 -2
  15. elasticsearch/_async/client/graph.py +1 -1
  16. elasticsearch/_async/client/ilm.py +23 -22
  17. elasticsearch/_async/client/indices.py +424 -132
  18. elasticsearch/_async/client/inference.py +1853 -115
  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 +141 -112
  24. elasticsearch/_async/client/monitoring.py +1 -1
  25. elasticsearch/_async/client/nodes.py +9 -27
  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 +71 -71
  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 +13 -17
  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 +22 -14
  42. elasticsearch/_async/client/xpack.py +2 -2
  43. elasticsearch/_async/helpers.py +0 -1
  44. elasticsearch/_sync/client/__init__.py +174 -79
  45. elasticsearch/_sync/client/_base.py +0 -1
  46. elasticsearch/_sync/client/async_search.py +12 -8
  47. elasticsearch/_sync/client/autoscaling.py +4 -4
  48. elasticsearch/_sync/client/cat.py +26 -26
  49. elasticsearch/_sync/client/ccr.py +186 -72
  50. elasticsearch/_sync/client/cluster.py +38 -19
  51. elasticsearch/_sync/client/connector.py +30 -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 +62 -6
  56. elasticsearch/_sync/client/features.py +12 -2
  57. elasticsearch/_sync/client/fleet.py +8 -2
  58. elasticsearch/_sync/client/graph.py +1 -1
  59. elasticsearch/_sync/client/ilm.py +23 -22
  60. elasticsearch/_sync/client/indices.py +424 -132
  61. elasticsearch/_sync/client/inference.py +1853 -115
  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 +141 -112
  67. elasticsearch/_sync/client/monitoring.py +1 -1
  68. elasticsearch/_sync/client/nodes.py +9 -27
  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 +71 -71
  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 +13 -17
  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 -3
  85. elasticsearch/_sync/client/watcher.py +22 -14
  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 +233 -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 +226 -0
  102. elasticsearch/dsl/_sync/update_by_query.py +45 -0
  103. elasticsearch/dsl/aggs.py +3730 -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 +4254 -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 +2816 -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 +1040 -0
  124. elasticsearch/dsl/serializer.py +34 -0
  125. elasticsearch/dsl/types.py +6471 -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 +119 -0
  130. {elasticsearch-8.17.2.dist-info → elasticsearch-8.18.0.dist-info}/METADATA +12 -2
  131. elasticsearch-8.18.0.dist-info/RECORD +161 -0
  132. elasticsearch-8.17.2.dist-info/RECORD +0 -119
  133. {elasticsearch-8.17.2.dist-info → elasticsearch-8.18.0.dist-info}/WHEEL +0 -0
  134. {elasticsearch-8.17.2.dist-info → elasticsearch-8.18.0.dist-info}/licenses/LICENSE +0 -0
  135. {elasticsearch-8.17.2.dist-info → elasticsearch-8.18.0.dist-info}/licenses/NOTICE +0 -0
@@ -0,0 +1,444 @@
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
+ from datetime import date, datetime
19
+ from fnmatch import fnmatch
20
+ from typing import (
21
+ TYPE_CHECKING,
22
+ Any,
23
+ Callable,
24
+ ClassVar,
25
+ Dict,
26
+ Generic,
27
+ List,
28
+ Optional,
29
+ Tuple,
30
+ TypeVar,
31
+ Union,
32
+ get_args,
33
+ overload,
34
+ )
35
+
36
+ try:
37
+ from types import UnionType
38
+ except ImportError:
39
+ UnionType = None # type: ignore[assignment, misc]
40
+
41
+ from typing_extensions import dataclass_transform
42
+
43
+ from .exceptions import ValidationException
44
+ from .field import Binary, Boolean, Date, Field, Float, Integer, Nested, Object, Text
45
+ from .mapping import Mapping
46
+ from .utils import DOC_META_FIELDS, ObjectBase
47
+
48
+ if TYPE_CHECKING:
49
+ from elastic_transport import ObjectApiResponse
50
+
51
+ from .index_base import IndexBase
52
+
53
+
54
+ class MetaField:
55
+ def __init__(self, *args: Any, **kwargs: Any):
56
+ self.args, self.kwargs = args, kwargs
57
+
58
+
59
+ class InstrumentedField:
60
+ """Proxy object for a mapped document field.
61
+
62
+ An object of this instance is returned when a field is accessed as a class
63
+ attribute of a ``Document`` or ``InnerDoc`` subclass. These objects can
64
+ be used in any situation in which a reference to a field is required, such
65
+ as when specifying sort options in a search::
66
+
67
+ class MyDocument(Document):
68
+ name: str
69
+
70
+ s = MyDocument.search()
71
+ s = s.sort(-MyDocument.name) # sort by name in descending order
72
+ """
73
+
74
+ def __init__(self, name: str, field: Field):
75
+ self._name = name
76
+ self._field = field
77
+
78
+ # note that the return value type here assumes classes will only be used to
79
+ # access fields (I haven't found a way to make this type dynamic based on a
80
+ # decision taken at runtime)
81
+ def __getattr__(self, attr: str) -> "InstrumentedField":
82
+ try:
83
+ # first let's see if this is an attribute of this object
84
+ return super().__getattribute__(attr) # type: ignore[no-any-return]
85
+ except AttributeError:
86
+ try:
87
+ # next we see if we have a sub-field with this name
88
+ return InstrumentedField(f"{self._name}.{attr}", self._field[attr])
89
+ except KeyError:
90
+ # lastly we let the wrapped field resolve this attribute
91
+ return getattr(self._field, attr) # type: ignore[no-any-return]
92
+
93
+ def __pos__(self) -> str:
94
+ """Return the field name representation for ascending sort order"""
95
+ return f"{self._name}"
96
+
97
+ def __neg__(self) -> str:
98
+ """Return the field name representation for descending sort order"""
99
+ return f"-{self._name}"
100
+
101
+ def __str__(self) -> str:
102
+ return self._name
103
+
104
+ def __repr__(self) -> str:
105
+ return f"InstrumentedField[{self._name}]"
106
+
107
+
108
+ class DocumentMeta(type):
109
+ _doc_type: "DocumentOptions"
110
+ _index: "IndexBase"
111
+
112
+ def __new__(
113
+ cls, name: str, bases: Tuple[type, ...], attrs: Dict[str, Any]
114
+ ) -> "DocumentMeta":
115
+ # DocumentMeta filters attrs in place
116
+ attrs["_doc_type"] = DocumentOptions(name, bases, attrs)
117
+ return super().__new__(cls, name, bases, attrs)
118
+
119
+ def __getattr__(cls, attr: str) -> Any:
120
+ if attr in cls._doc_type.mapping:
121
+ return InstrumentedField(attr, cls._doc_type.mapping[attr])
122
+ return super().__getattribute__(attr)
123
+
124
+
125
+ class DocumentOptions:
126
+ type_annotation_map = {
127
+ int: (Integer, {}),
128
+ float: (Float, {}),
129
+ bool: (Boolean, {}),
130
+ str: (Text, {}),
131
+ bytes: (Binary, {}),
132
+ datetime: (Date, {}),
133
+ date: (Date, {"format": "yyyy-MM-dd"}),
134
+ }
135
+
136
+ def __init__(self, name: str, bases: Tuple[type, ...], attrs: Dict[str, Any]):
137
+ meta = attrs.pop("Meta", None)
138
+
139
+ # create the mapping instance
140
+ self.mapping: Mapping = getattr(meta, "mapping", Mapping())
141
+
142
+ # register the document's fields, which can be given in a few formats:
143
+ #
144
+ # class MyDocument(Document):
145
+ # # required field using native typing
146
+ # # (str, int, float, bool, datetime, date)
147
+ # field1: str
148
+ #
149
+ # # optional field using native typing
150
+ # field2: Optional[datetime]
151
+ #
152
+ # # array field using native typing
153
+ # field3: list[int]
154
+ #
155
+ # # sub-object, same as Object(MyInnerDoc)
156
+ # field4: MyInnerDoc
157
+ #
158
+ # # nested sub-objects, same as Nested(MyInnerDoc)
159
+ # field5: list[MyInnerDoc]
160
+ #
161
+ # # use typing, but override with any stock or custom field
162
+ # field6: bool = MyCustomField()
163
+ #
164
+ # # best mypy and pyright support and dataclass-like behavior
165
+ # field7: M[date]
166
+ # field8: M[str] = mapped_field(MyCustomText(), default="foo")
167
+ #
168
+ # # legacy format without Python typing
169
+ # field9 = Text()
170
+ #
171
+ # # ignore attributes
172
+ # field10: ClassVar[string] = "a regular class variable"
173
+ annotations = attrs.get("__annotations__", {})
174
+ fields = set([n for n in attrs if isinstance(attrs[n], Field)])
175
+ fields.update(annotations.keys())
176
+ field_defaults = {}
177
+ for name in fields:
178
+ value: Any = None
179
+ required = None
180
+ multi = None
181
+ if name in annotations:
182
+ # the field has a type annotation, so next we try to figure out
183
+ # what field type we can use
184
+ type_ = annotations[name]
185
+ skip = False
186
+ required = True
187
+ multi = False
188
+ while hasattr(type_, "__origin__"):
189
+ if type_.__origin__ == ClassVar:
190
+ skip = True
191
+ break
192
+ elif type_.__origin__ == Mapped:
193
+ # M[type] -> extract the wrapped type
194
+ type_ = type_.__args__[0]
195
+ elif type_.__origin__ == Union:
196
+ if len(type_.__args__) == 2 and type_.__args__[1] is type(None):
197
+ # Optional[type] -> mark instance as optional
198
+ required = False
199
+ type_ = type_.__args__[0]
200
+ else:
201
+ raise TypeError("Unsupported union")
202
+ elif type_.__origin__ in [list, List]:
203
+ # List[type] -> mark instance as multi
204
+ multi = True
205
+ required = False
206
+ type_ = type_.__args__[0]
207
+ else:
208
+ break
209
+ if skip or type_ == ClassVar:
210
+ # skip ClassVar attributes
211
+ continue
212
+ if type(type_) is UnionType:
213
+ # a union given with the pipe syntax
214
+ args = get_args(type_)
215
+ if len(args) == 2 and args[1] is type(None):
216
+ required = False
217
+ type_ = type_.__args__[0]
218
+ else:
219
+ raise TypeError("Unsupported union")
220
+ field = None
221
+ field_args: List[Any] = []
222
+ field_kwargs: Dict[str, Any] = {}
223
+ if isinstance(type_, type) and issubclass(type_, InnerDoc):
224
+ # object or nested field
225
+ field = Nested if multi else Object
226
+ field_args = [type_]
227
+ elif type_ in self.type_annotation_map:
228
+ # use best field type for the type hint provided
229
+ field, field_kwargs = self.type_annotation_map[type_] # type: ignore[assignment]
230
+
231
+ if field:
232
+ field_kwargs = {
233
+ "multi": multi,
234
+ "required": required,
235
+ **field_kwargs,
236
+ }
237
+ value = field(*field_args, **field_kwargs)
238
+
239
+ if name in attrs:
240
+ # this field has a right-side value, which can be field
241
+ # instance on its own or wrapped with mapped_field()
242
+ attr_value = attrs[name]
243
+ if isinstance(attr_value, dict):
244
+ # the mapped_field() wrapper function was used so we need
245
+ # to look for the field instance and also record any
246
+ # dataclass-style defaults
247
+ attr_value = attrs[name].get("_field")
248
+ default_value = attrs[name].get("default") or attrs[name].get(
249
+ "default_factory"
250
+ )
251
+ if default_value:
252
+ field_defaults[name] = default_value
253
+ if attr_value:
254
+ value = attr_value
255
+ if required is not None:
256
+ value._required = required
257
+ if multi is not None:
258
+ value._multi = multi
259
+
260
+ if value is None:
261
+ raise TypeError(f"Cannot map field {name}")
262
+
263
+ self.mapping.field(name, value)
264
+ if name in attrs:
265
+ del attrs[name]
266
+
267
+ # store dataclass-style defaults for ObjectBase.__init__ to assign
268
+ attrs["_defaults"] = field_defaults
269
+
270
+ # add all the mappings for meta fields
271
+ for name in dir(meta):
272
+ if isinstance(getattr(meta, name, None), MetaField):
273
+ params = getattr(meta, name)
274
+ self.mapping.meta(name, *params.args, **params.kwargs)
275
+
276
+ # document inheritance - include the fields from parents' mappings
277
+ for b in bases:
278
+ if hasattr(b, "_doc_type") and hasattr(b._doc_type, "mapping"):
279
+ self.mapping.update(b._doc_type.mapping, update_only=True)
280
+
281
+ @property
282
+ def name(self) -> str:
283
+ return self.mapping.properties.name
284
+
285
+
286
+ _FieldType = TypeVar("_FieldType")
287
+
288
+
289
+ class Mapped(Generic[_FieldType]):
290
+ """Class that represents the type of a mapped field.
291
+
292
+ This class can be used as an optional wrapper on a field type to help type
293
+ checkers assign the correct type when the field is used as a class
294
+ attribute.
295
+
296
+ Consider the following definitions::
297
+
298
+ class MyDocument(Document):
299
+ first: str
300
+ second: M[str]
301
+
302
+ mydoc = MyDocument(first="1", second="2")
303
+
304
+ Type checkers have no trouble inferring the type of both ``mydoc.first``
305
+ and ``mydoc.second`` as ``str``, but while ``MyDocument.first`` will be
306
+ incorrectly typed as ``str``, ``MyDocument.second`` should be assigned the
307
+ correct ``InstrumentedField`` type.
308
+ """
309
+
310
+ __slots__: Dict[str, Any] = {}
311
+
312
+ if TYPE_CHECKING:
313
+
314
+ @overload
315
+ def __get__(self, instance: None, owner: Any) -> InstrumentedField: ...
316
+
317
+ @overload
318
+ def __get__(self, instance: object, owner: Any) -> _FieldType: ...
319
+
320
+ def __get__(
321
+ self, instance: Optional[object], owner: Any
322
+ ) -> Union[InstrumentedField, _FieldType]: ...
323
+
324
+ def __set__(self, instance: Optional[object], value: _FieldType) -> None: ...
325
+
326
+ def __delete__(self, instance: Any) -> None: ...
327
+
328
+
329
+ M = Mapped
330
+
331
+
332
+ def mapped_field(
333
+ field: Optional[Field] = None,
334
+ *,
335
+ init: bool = True,
336
+ default: Any = None,
337
+ default_factory: Optional[Callable[[], Any]] = None,
338
+ **kwargs: Any,
339
+ ) -> Any:
340
+ """Construct a field using dataclass behaviors
341
+
342
+ This function can be used in the right side of a document field definition
343
+ as a wrapper for the field instance or as a way to provide dataclass-compatible
344
+ options.
345
+
346
+ :param field: The instance of ``Field`` to use for this field. If not provided,
347
+ an instance that is appropriate for the type given to the field is used.
348
+ :param init: a value of ``True`` adds this field to the constructor, and a
349
+ value of ``False`` omits it from it. The default is ``True``.
350
+ :param default: a default value to use for this field when one is not provided
351
+ explicitly.
352
+ :param default_factory: a callable that returns a default value for the field,
353
+ when one isn't provided explicitly. Only one of ``factory`` and
354
+ ``default_factory`` can be used.
355
+ """
356
+ return {
357
+ "_field": field,
358
+ "init": init,
359
+ "default": default,
360
+ "default_factory": default_factory,
361
+ **kwargs,
362
+ }
363
+
364
+
365
+ @dataclass_transform(field_specifiers=(mapped_field,))
366
+ class InnerDoc(ObjectBase, metaclass=DocumentMeta):
367
+ """
368
+ Common class for inner documents like Object or Nested
369
+ """
370
+
371
+ @classmethod
372
+ def from_es(
373
+ cls,
374
+ data: Union[Dict[str, Any], "ObjectApiResponse[Any]"],
375
+ data_only: bool = False,
376
+ ) -> "InnerDoc":
377
+ if data_only:
378
+ data = {"_source": data}
379
+ return super().from_es(data)
380
+
381
+
382
+ class DocumentBase(ObjectBase):
383
+ """
384
+ Model-like class for persisting documents in elasticsearch.
385
+ """
386
+
387
+ @classmethod
388
+ def _matches(cls, hit: Dict[str, Any]) -> bool:
389
+ if cls._index._name is None:
390
+ return True
391
+ return fnmatch(hit.get("_index", ""), cls._index._name)
392
+
393
+ @classmethod
394
+ def _default_index(cls, index: Optional[str] = None) -> str:
395
+ return index or cls._index._name
396
+
397
+ def _get_index(
398
+ self, index: Optional[str] = None, required: bool = True
399
+ ) -> Optional[str]:
400
+ if index is None:
401
+ index = getattr(self.meta, "index", None)
402
+ if index is None:
403
+ index = getattr(self._index, "_name", None)
404
+ if index is None and required:
405
+ raise ValidationException("No index")
406
+ if index and "*" in index:
407
+ raise ValidationException("You cannot write to a wildcard index.")
408
+ return index
409
+
410
+ def __repr__(self) -> str:
411
+ return "{}({})".format(
412
+ self.__class__.__name__,
413
+ ", ".join(
414
+ f"{key}={getattr(self.meta, key)!r}"
415
+ for key in ("index", "id")
416
+ if key in self.meta
417
+ ),
418
+ )
419
+
420
+ def to_dict(self, include_meta: bool = False, skip_empty: bool = True) -> Dict[str, Any]: # type: ignore[override]
421
+ """
422
+ Serialize the instance into a dictionary so that it can be saved in elasticsearch.
423
+
424
+ :arg include_meta: if set to ``True`` will include all the metadata
425
+ (``_index``, ``_id`` etc). Otherwise just the document's
426
+ data is serialized. This is useful when passing multiple instances into
427
+ ``elasticsearch.helpers.bulk``.
428
+ :arg skip_empty: if set to ``False`` will cause empty values (``None``,
429
+ ``[]``, ``{}``) to be left on the document. Those values will be
430
+ stripped out otherwise as they make no difference in elasticsearch.
431
+ """
432
+ d = super().to_dict(skip_empty=skip_empty)
433
+ if not include_meta:
434
+ return d
435
+
436
+ meta = {"_" + k: self.meta[k] for k in DOC_META_FIELDS if k in self.meta}
437
+
438
+ # in case of to_dict include the index unlike save/update/delete
439
+ index = self._get_index(required=False)
440
+ if index is not None:
441
+ meta["_index"] = index
442
+
443
+ meta["_source"] = d
444
+ return meta
@@ -0,0 +1,32 @@
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
+
19
+ class ElasticsearchDslException(Exception):
20
+ pass
21
+
22
+
23
+ class UnknownDslObject(ElasticsearchDslException):
24
+ pass
25
+
26
+
27
+ class ValidationException(ValueError, ElasticsearchDslException):
28
+ pass
29
+
30
+
31
+ class IllegalOperation(ElasticsearchDslException):
32
+ pass
@@ -0,0 +1,28 @@
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
+ from ._async.faceted_search import AsyncFacetedSearch # noqa: F401
19
+ from ._sync.faceted_search import FacetedSearch # noqa: F401
20
+ from .faceted_search_base import ( # noqa: F401
21
+ DateHistogramFacet,
22
+ Facet,
23
+ FacetedResponse,
24
+ HistogramFacet,
25
+ NestedFacet,
26
+ RangeFacet,
27
+ TermsFacet,
28
+ )