You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* ability to rename document fields
* lint fixes
* dict to obj support
* lint fixes
* lint fixes
* use es_name, and also expose this option in mapped_field
* support for data stream templates and bulk upload
* type hint fixes
* save implementation for data streams
* doc updates and example app
* vale suggestion
* minor fixes
* handling of more data stream operations
The `Document` instances use native python types such as `str` and `datetime` for its attributes. In case of `Object` or `Nested` fields an instance of the `InnerDoc` subclass is used, as in the `add_comment` method in the above example, where we are creating an instance of the `Comment` class.
1250
+
The `Document` instances can use native Python types such as `str` and `datetime` for its attributes. In case of `Object` or `Nested` fields an instance of the `InnerDoc` subclass is used, as in the `add_comment` method in the above example, where we are creating an instance of the `Comment` class.
1255
1251
1256
-
There are some specific types that were created to make working with some field types easier, for example the `Range` object used in any of the [range fields](elasticsearch://reference/elasticsearch/mapping-reference/range.md):
1252
+
There are also specific type classes that were created to make working with some field types easier, for example the `Range` object used in any of the [range fields](elasticsearch://reference/elasticsearch/mapping-reference/range.md):
1257
1253
1258
1254
::::{tab-set}
1259
1255
:group: sync_or_async
@@ -1351,7 +1347,7 @@ class Post(AsyncDocument):
1351
1347
1352
1348
::::
1353
1349
1354
-
::::{note}
1350
+
:::::{note}
1355
1351
When using `Field` subclasses such as `Text`, `Date` and `Boolean` to define attributes, these classes must be given in the right-hand side.
1356
1352
1357
1353
::::{tab-set}
@@ -1378,7 +1374,7 @@ class Post(AsyncDocument):
1378
1374
::::
1379
1375
1380
1376
Using a `Field` subclass as a Python type hint will result in errors.
1381
-
::::
1377
+
:::::
1382
1378
1383
1379
Python types are mapped to their corresponding `Field` types according to the following table:
1384
1380
@@ -1668,8 +1664,54 @@ class Post(AsyncDocument):
1668
1664
1669
1665
::::
1670
1666
1671
-
In that case any `datetime` object passed in (or parsed from elasticsearch) will be treated as if it were in `UTC` timezone.
1667
+
In that case any `datetime` object passed in (or parsed from Elasticsearch) will be treated as if it were in `UTC` timezone.
1668
+
1669
+
1670
+
#### Custom field names
1671
+
1672
+
By default, the `Document` and `AsyncDocument` classes use the names given to the field attributes as the field names in the Elasticsearch index. But sometimes it is necessary for the names of a field in Python and Elasticsearch to be different, such as when the Elasticsearch name is not a valid Python identifier.
1673
+
1674
+
The following example shows how to define the Elasticsearch field `@timestamp`, used with data streams:
If using `Field` subclasses to define attribute types, the `_es_name` argument can be passed with the desired Elasticsearch name:
1695
+
1696
+
:::{tab-item} Standard Python
1697
+
:sync: sync
1698
+
```python
1699
+
classMyDoc(Document):
1700
+
timestamp = Date(_es_name='@timestamp')
1701
+
```
1702
+
:::
1703
+
1704
+
:::{tab-item} Async Python
1705
+
:sync: async
1706
+
```python
1707
+
classMyDoc(AsyncDocument):
1708
+
timestamp = Date(_es_name='@timestamp')
1709
+
```
1710
+
:::
1711
+
1712
+
::::
1672
1713
1714
+
The conversion between the Python and Elasticsearch names happens automatically during serialization and deserialization of `Document` and `AsyncDocument` instances. The Elasticsearch field names must be used when sending requests outside of the document classes. Likewise, responses from Elasticsearch that are not deserialized to a document class will reference the Elasticsearch field names.
1673
1715
1674
1716
#### Document life cycle [life-cycle]
1675
1717
@@ -2341,6 +2383,7 @@ This section of the `Document` definition can contain any information about the
2341
2383
*`settings`: dictionary containing any settings for the `Index` object like `number_of_shards`.
2342
2384
*`analyzers`: additional list of analyzers that should be defined on an index (see `analysis` for details).
2343
2385
*`aliases`: dictionary with any aliases definitions
2386
+
*`data_stream`: set to `True` to configure a data stream instead of an index.
The DSL module also exposes an option to manage [index templates](docs-content://manage-data/data-store/templates.md) in elasticsearch using the `ComposableIndexTemplate` and `IndexTemplate` classes, which have a similar API to `Index`.
2551
2594
2552
2595
::::{note}
2553
-
Composable index templates should be always be preferred over the legacy index templates, since the latter are deprecated.
2596
+
Composable index templates should always be preferred over the legacy index templates.
0 commit comments