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
Copy file name to clipboardExpand all lines: docs/reference/dsl_how_to_guides.md
+8-4Lines changed: 8 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1247,7 +1247,7 @@ class Post(AsyncDocument):
1247
1247
1248
1248
#### Data types [_data_types]
1249
1249
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.
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.
1251
1251
1252
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):
1253
1253
@@ -1664,12 +1664,14 @@ class Post(AsyncDocument):
1664
1664
1665
1665
::::
1666
1666
1667
-
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
1668
1669
1669
1670
1670
#### Custom field names
1671
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. There cases, however, where it is necessary for the names of a field in Python and Elasticsearch to be different.
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:
1673
1675
1674
1676
:::{tab-item} Standard Python
1675
1677
:sync: sync
@@ -1709,6 +1711,8 @@ class MyDoc(AsyncDocument):
1709
1711
1710
1712
::::
1711
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.
1715
+
1712
1716
#### Document life cycle [life-cycle]
1713
1717
1714
1718
Before you first use the `Post` document type, you need to create the mappings in Elasticsearch. For that you can either use the `index` object or create the mappings directly by calling the `init` class method:
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`.
2590
2594
2591
2595
::::{note}
2592
-
Composable index templates should always be preferred over the legacy index templates, which are deprecated.
2596
+
Composable index templates should always be preferred over the legacy index templates.
0 commit comments