elasticsearch9 9.1.3__py3-none-any.whl → 9.2.1__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 (60) hide show
  1. elasticsearch9/_async/client/__init__.py +91 -24
  2. elasticsearch9/_async/client/async_search.py +7 -0
  3. elasticsearch9/_async/client/autoscaling.py +7 -0
  4. elasticsearch9/_async/client/cat.py +8 -1
  5. elasticsearch9/_async/client/cluster.py +7 -7
  6. elasticsearch9/_async/client/eql.py +7 -0
  7. elasticsearch9/_async/client/esql.py +26 -3
  8. elasticsearch9/_async/client/indices.py +153 -7
  9. elasticsearch9/_async/client/inference.py +315 -42
  10. elasticsearch9/_async/client/ingest.py +8 -0
  11. elasticsearch9/_async/client/license.py +4 -2
  12. elasticsearch9/_async/client/ml.py +2 -2
  13. elasticsearch9/_async/client/nodes.py +2 -4
  14. elasticsearch9/_async/client/project.py +68 -0
  15. elasticsearch9/_async/client/security.py +39 -0
  16. elasticsearch9/_async/client/shutdown.py +6 -0
  17. elasticsearch9/_async/client/simulate.py +8 -0
  18. elasticsearch9/_async/client/snapshot.py +20 -10
  19. elasticsearch9/_async/client/sql.py +7 -0
  20. elasticsearch9/_async/client/streams.py +2 -3
  21. elasticsearch9/_async/helpers.py +28 -15
  22. elasticsearch9/_sync/client/__init__.py +91 -24
  23. elasticsearch9/_sync/client/async_search.py +7 -0
  24. elasticsearch9/_sync/client/autoscaling.py +7 -0
  25. elasticsearch9/_sync/client/cat.py +8 -1
  26. elasticsearch9/_sync/client/cluster.py +7 -7
  27. elasticsearch9/_sync/client/eql.py +7 -0
  28. elasticsearch9/_sync/client/esql.py +26 -3
  29. elasticsearch9/_sync/client/indices.py +153 -7
  30. elasticsearch9/_sync/client/inference.py +315 -42
  31. elasticsearch9/_sync/client/ingest.py +8 -0
  32. elasticsearch9/_sync/client/license.py +4 -2
  33. elasticsearch9/_sync/client/ml.py +2 -2
  34. elasticsearch9/_sync/client/nodes.py +2 -4
  35. elasticsearch9/_sync/client/project.py +68 -0
  36. elasticsearch9/_sync/client/security.py +39 -0
  37. elasticsearch9/_sync/client/shutdown.py +6 -0
  38. elasticsearch9/_sync/client/simulate.py +8 -0
  39. elasticsearch9/_sync/client/snapshot.py +20 -10
  40. elasticsearch9/_sync/client/sql.py +7 -0
  41. elasticsearch9/_sync/client/streams.py +2 -3
  42. elasticsearch9/_version.py +2 -2
  43. elasticsearch9/client.py +2 -0
  44. elasticsearch9/compat.py +2 -15
  45. elasticsearch9/dsl/_async/document.py +2 -1
  46. elasticsearch9/dsl/_sync/document.py +2 -1
  47. elasticsearch9/dsl/document_base.py +38 -13
  48. elasticsearch9/dsl/field.py +8 -0
  49. elasticsearch9/dsl/pydantic.py +152 -0
  50. elasticsearch9/dsl/query.py +5 -1
  51. elasticsearch9/dsl/search_base.py +5 -1
  52. elasticsearch9/dsl/types.py +37 -9
  53. elasticsearch9/esql/esql.py +331 -41
  54. elasticsearch9/esql/functions.py +88 -0
  55. elasticsearch9/helpers/actions.py +1 -1
  56. {elasticsearch9-9.1.3.dist-info → elasticsearch9-9.2.1.dist-info}/METADATA +26 -4
  57. {elasticsearch9-9.1.3.dist-info → elasticsearch9-9.2.1.dist-info}/RECORD +60 -57
  58. {elasticsearch9-9.1.3.dist-info → elasticsearch9-9.2.1.dist-info}/WHEEL +0 -0
  59. {elasticsearch9-9.1.3.dist-info → elasticsearch9-9.2.1.dist-info}/licenses/LICENSE +0 -0
  60. {elasticsearch9-9.1.3.dist-info → elasticsearch9-9.2.1.dist-info}/licenses/NOTICE +0 -0
@@ -0,0 +1,152 @@
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 typing import Any, ClassVar, Dict, List, Optional, Tuple, Type
19
+
20
+ from pydantic import BaseModel, Field, PrivateAttr
21
+ from typing_extensions import Annotated, Self, dataclass_transform
22
+
23
+ from .. import dsl
24
+
25
+
26
+ class ESMeta(BaseModel):
27
+ """Metadata items associated with Elasticsearch documents."""
28
+
29
+ id: str = ""
30
+ index: str = ""
31
+ primary_term: int = 0
32
+ seq_no: int = 0
33
+ version: int = 0
34
+ score: float = 0
35
+
36
+
37
+ class _BaseModel(BaseModel):
38
+ meta: Annotated[ESMeta, dsl.mapped_field(exclude=True)] = Field(
39
+ default=ESMeta(),
40
+ init=False,
41
+ )
42
+
43
+
44
+ class _BaseESModelMetaclass(type(BaseModel)): # type: ignore[misc]
45
+ """Generic metaclass methods for BaseEsModel and AsyncBaseESModel."""
46
+
47
+ @staticmethod
48
+ def process_annotations(
49
+ metacls: Type["_BaseESModelMetaclass"], annotations: Dict[str, Any]
50
+ ) -> Dict[str, Any]:
51
+ """Process Pydantic typing annotations and adapt them so that they can
52
+ be used to create the Elasticsearch document.
53
+ """
54
+ updated_annotations = {}
55
+ for var, ann in annotations.items():
56
+ if isinstance(ann, type(BaseModel)):
57
+ # an inner Pydantic model is transformed into an Object field
58
+ updated_annotations[var] = metacls.make_dsl_class(
59
+ metacls, dsl.InnerDoc, ann
60
+ )
61
+ elif (
62
+ hasattr(ann, "__origin__")
63
+ and ann.__origin__ in [list, List]
64
+ and isinstance(ann.__args__[0], type(BaseModel))
65
+ ):
66
+ # an inner list of Pydantic models is transformed into a Nested field
67
+ updated_annotations[var] = List[ # type: ignore[assignment,misc]
68
+ metacls.make_dsl_class(metacls, dsl.InnerDoc, ann.__args__[0])
69
+ ]
70
+ else:
71
+ updated_annotations[var] = ann
72
+ return updated_annotations
73
+
74
+ @staticmethod
75
+ def make_dsl_class(
76
+ metacls: Type["_BaseESModelMetaclass"],
77
+ dsl_class: type,
78
+ pydantic_model: type,
79
+ pydantic_attrs: Optional[Dict[str, Any]] = None,
80
+ ) -> type:
81
+ """Create a DSL document class dynamically, using the structure of a
82
+ Pydantic model."""
83
+ dsl_attrs = {
84
+ attr: value
85
+ for attr, value in dsl_class.__dict__.items()
86
+ if not attr.startswith("__")
87
+ }
88
+ pydantic_attrs = {
89
+ **(pydantic_attrs or {}),
90
+ "__annotations__": metacls.process_annotations(
91
+ metacls, pydantic_model.__annotations__
92
+ ),
93
+ }
94
+ return type(dsl_class)(
95
+ f"_ES{pydantic_model.__name__}",
96
+ (dsl_class,),
97
+ {
98
+ **pydantic_attrs,
99
+ **dsl_attrs,
100
+ "__qualname__": f"_ES{pydantic_model.__name__}",
101
+ },
102
+ )
103
+
104
+
105
+ class BaseESModelMetaclass(_BaseESModelMetaclass):
106
+ """Metaclass for the BaseESModel class."""
107
+
108
+ def __new__(cls, name: str, bases: Tuple[type, ...], attrs: Dict[str, Any]) -> Any:
109
+ model = super().__new__(cls, name, bases, attrs)
110
+ model._doc = cls.make_dsl_class(cls, dsl.Document, model, attrs)
111
+ return model
112
+
113
+
114
+ class AsyncBaseESModelMetaclass(_BaseESModelMetaclass):
115
+ """Metaclass for the AsyncBaseESModel class."""
116
+
117
+ def __new__(cls, name: str, bases: Tuple[type, ...], attrs: Dict[str, Any]) -> Any:
118
+ model = super().__new__(cls, name, bases, attrs)
119
+ model._doc = cls.make_dsl_class(cls, dsl.AsyncDocument, model, attrs)
120
+ return model
121
+
122
+
123
+ @dataclass_transform(kw_only_default=True, field_specifiers=(Field, PrivateAttr))
124
+ class BaseESModel(_BaseModel, metaclass=BaseESModelMetaclass):
125
+ _doc: ClassVar[Type[dsl.Document]]
126
+
127
+ def to_doc(self) -> dsl.Document:
128
+ """Convert this model to an Elasticsearch document."""
129
+ data = self.model_dump()
130
+ meta = {f"_{k}": v for k, v in data.pop("meta", {}).items() if v}
131
+ return self._doc(**meta, **data)
132
+
133
+ @classmethod
134
+ def from_doc(cls, dsl_obj: dsl.Document) -> Self:
135
+ """Create a model from the given Elasticsearch document."""
136
+ return cls(meta=ESMeta(**dsl_obj.meta.to_dict()), **dsl_obj.to_dict())
137
+
138
+
139
+ @dataclass_transform(kw_only_default=True, field_specifiers=(Field, PrivateAttr))
140
+ class AsyncBaseESModel(_BaseModel, metaclass=AsyncBaseESModelMetaclass):
141
+ _doc: ClassVar[Type[dsl.AsyncDocument]]
142
+
143
+ def to_doc(self) -> dsl.AsyncDocument:
144
+ """Convert this model to an Elasticsearch document."""
145
+ data = self.model_dump()
146
+ meta = {f"_{k}": v for k, v in data.pop("meta", {}).items() if v}
147
+ return self._doc(**meta, **data)
148
+
149
+ @classmethod
150
+ def from_doc(cls, dsl_obj: dsl.AsyncDocument) -> Self:
151
+ """Create a model from the given Elasticsearch document."""
152
+ return cls(meta=ESMeta(**dsl_obj.meta.to_dict()), **dsl_obj.to_dict())
@@ -1087,6 +1087,8 @@ class Knn(Query):
1087
1087
  a query_vector_builder or query_vector, but not both.
1088
1088
  :arg num_candidates: The number of nearest neighbor candidates to
1089
1089
  consider per shard
1090
+ :arg visit_percentage: The percentage of vectors to explore per shard
1091
+ while doing knn search with bbq_disk
1090
1092
  :arg k: The final number of nearest neighbors to return as top hits
1091
1093
  :arg filter: Filters for the kNN search query
1092
1094
  :arg similarity: The minimum similarity for a vector to be considered
@@ -1115,6 +1117,7 @@ class Knn(Query):
1115
1117
  "types.QueryVectorBuilder", Dict[str, Any], "DefaultType"
1116
1118
  ] = DEFAULT,
1117
1119
  num_candidates: Union[int, "DefaultType"] = DEFAULT,
1120
+ visit_percentage: Union[float, "DefaultType"] = DEFAULT,
1118
1121
  k: Union[int, "DefaultType"] = DEFAULT,
1119
1122
  filter: Union[Query, Sequence[Query], "DefaultType"] = DEFAULT,
1120
1123
  similarity: Union[float, "DefaultType"] = DEFAULT,
@@ -1130,6 +1133,7 @@ class Knn(Query):
1130
1133
  query_vector=query_vector,
1131
1134
  query_vector_builder=query_vector_builder,
1132
1135
  num_candidates=num_candidates,
1136
+ visit_percentage=visit_percentage,
1133
1137
  k=k,
1134
1138
  filter=filter,
1135
1139
  similarity=similarity,
@@ -1445,7 +1449,7 @@ class MoreLikeThis(Query):
1445
1449
  ] = DEFAULT,
1446
1450
  version: Union[int, "DefaultType"] = DEFAULT,
1447
1451
  version_type: Union[
1448
- Literal["internal", "external", "external_gte", "force"], "DefaultType"
1452
+ Literal["internal", "external", "external_gte"], "DefaultType"
1449
1453
  ] = DEFAULT,
1450
1454
  boost: Union[float, "DefaultType"] = DEFAULT,
1451
1455
  _name: Union[str, "DefaultType"] = DEFAULT,
@@ -721,14 +721,18 @@ class SearchBase(Request[_R]):
721
721
 
722
722
  def ensure_strings(
723
723
  fields: Union[
724
+ bool,
724
725
  str,
725
726
  "InstrumentedField",
726
727
  List[Union[str, "InstrumentedField"]],
727
728
  Dict[str, List[Union[str, "InstrumentedField"]]],
728
729
  ],
729
- ) -> Union[str, List[str], Dict[str, List[str]]]:
730
+ ) -> Union[bool, str, List[str], Dict[str, List[str]]]:
730
731
  if isinstance(fields, dict):
731
732
  return {k: ensure_strings(v) for k, v in fields.items()}
733
+ elif isinstance(fields, bool):
734
+ # boolean settings should stay the way they are
735
+ return fields
732
736
  elif not isinstance(fields, (str, InstrumentedField)):
733
737
  # we assume that if `fields` is not a any of [dict, str,
734
738
  # InstrumentedField] then it is an iterable of strings or
@@ -151,9 +151,10 @@ class ChunkingSettings(AttrDict[Any]):
151
151
  strategies in the linked documentation. Defaults to `sentence` if
152
152
  omitted.
153
153
  :arg max_chunk_size: (required) The maximum size of a chunk in words.
154
- This value cannot be higher than `300` or lower than `20` (for
155
- `sentence` strategy) or `10` (for `word` strategy). Defaults to
156
- `250` if omitted.
154
+ This value cannot be lower than `20` (for `sentence` strategy) or
155
+ `10` (for `word` strategy). This value should not exceed the
156
+ window size for the associated model. Defaults to `250` if
157
+ omitted.
157
158
  :arg separator_group: Only applicable to the `recursive` strategy and
158
159
  required when using it. Sets a predefined list of separators in
159
160
  the saved chunking settings based on the selected text type.
@@ -397,14 +398,15 @@ class DenseVectorIndexOptions(AttrDict[Any]):
397
398
  HNSW graph. Only applicable to `hnsw`, `int8_hnsw`, `bbq_hnsw`,
398
399
  and `int4_hnsw` index types. Defaults to `16` if omitted.
399
400
  :arg rescore_vector: The rescore vector options. This is only
400
- applicable to `bbq_hnsw`, `int4_hnsw`, `int8_hnsw`, `bbq_flat`,
401
- `int4_flat`, and `int8_flat` index types.
401
+ applicable to `bbq_disk`, `bbq_hnsw`, `int4_hnsw`, `int8_hnsw`,
402
+ `bbq_flat`, `int4_flat`, and `int8_flat` index types.
402
403
  """
403
404
 
404
405
  type: Union[
405
406
  Literal[
406
407
  "bbq_flat",
407
408
  "bbq_hnsw",
409
+ "bbq_disk",
408
410
  "flat",
409
411
  "hnsw",
410
412
  "int4_flat",
@@ -428,6 +430,7 @@ class DenseVectorIndexOptions(AttrDict[Any]):
428
430
  Literal[
429
431
  "bbq_flat",
430
432
  "bbq_hnsw",
433
+ "bbq_disk",
431
434
  "flat",
432
435
  "hnsw",
433
436
  "int4_flat",
@@ -2327,9 +2330,7 @@ class LikeDocument(AttrDict[Any]):
2327
2330
  per_field_analyzer: Union[Mapping[Union[str, InstrumentedField], str], DefaultType]
2328
2331
  routing: Union[str, DefaultType]
2329
2332
  version: Union[int, DefaultType]
2330
- version_type: Union[
2331
- Literal["internal", "external", "external_gte", "force"], DefaultType
2332
- ]
2333
+ version_type: Union[Literal["internal", "external", "external_gte"], DefaultType]
2333
2334
 
2334
2335
  def __init__(
2335
2336
  self,
@@ -2344,7 +2345,7 @@ class LikeDocument(AttrDict[Any]):
2344
2345
  routing: Union[str, DefaultType] = DEFAULT,
2345
2346
  version: Union[int, DefaultType] = DEFAULT,
2346
2347
  version_type: Union[
2347
- Literal["internal", "external", "external_gte", "force"], DefaultType
2348
+ Literal["internal", "external", "external_gte"], DefaultType
2348
2349
  ] = DEFAULT,
2349
2350
  **kwargs: Any,
2350
2351
  ):
@@ -3190,6 +3191,33 @@ class ScriptedHeuristic(AttrDict[Any]):
3190
3191
  super().__init__(kwargs)
3191
3192
 
3192
3193
 
3194
+ class SemanticTextIndexOptions(AttrDict[Any]):
3195
+ """
3196
+ :arg dense_vector:
3197
+ :arg sparse_vector:
3198
+ """
3199
+
3200
+ dense_vector: Union["DenseVectorIndexOptions", Dict[str, Any], DefaultType]
3201
+ sparse_vector: Union["SparseVectorIndexOptions", Dict[str, Any], DefaultType]
3202
+
3203
+ def __init__(
3204
+ self,
3205
+ *,
3206
+ dense_vector: Union[
3207
+ "DenseVectorIndexOptions", Dict[str, Any], DefaultType
3208
+ ] = DEFAULT,
3209
+ sparse_vector: Union[
3210
+ "SparseVectorIndexOptions", Dict[str, Any], DefaultType
3211
+ ] = DEFAULT,
3212
+ **kwargs: Any,
3213
+ ):
3214
+ if dense_vector is not DEFAULT:
3215
+ kwargs["dense_vector"] = dense_vector
3216
+ if sparse_vector is not DEFAULT:
3217
+ kwargs["sparse_vector"] = sparse_vector
3218
+ super().__init__(kwargs)
3219
+
3220
+
3193
3221
  class ShapeFieldQuery(AttrDict[Any]):
3194
3222
  """
3195
3223
  :arg indexed_shape: Queries using a pre-indexed shape.