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/source-serialization.md
+38-1Lines changed: 38 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,13 @@ mapped_pages:
8
8
Source serialization refers to the process of (de)serializing POCO types in consumer applications as source documents indexed and retrieved from {{es}}. A source serializer implementation handles serialization, with the default implementation using the `System.Text.Json` library. As a result, you may use `System.Text.Json` attributes and converters to control the serialization behavior.
9
9
10
10
-[Modelling documents with types](#modeling-documents-with-types)
11
+
-[Default behavior](#default-behaviour)
12
+
-[Using Elasticsearch types in documents](#elasticsearch-types-in-documents)
-[Creating a custom `Serializer`](#creating-custom-serializers)
12
18
-[Native AOT](#native-aot)
13
19
14
20
## Modeling documents with types [modeling-documents-with-types]
@@ -51,6 +57,34 @@ The index request is serialized, with the source serializer handling the `MyDocu
51
57
}
52
58
```
53
59
60
+
### Using Elasticsearch types in documents [elasticsearch-types-in-documents]
61
+
62
+
There are various cases where you might have a POCO type that contains an `Elastic.Clients.Elasticsearch` type as one of its properties.
63
+
64
+
For example, consider if you want to use percolation; you need to store {{es}} queries as part of the `_source` of your document, which means you need to have a POCO that looks like this:
1. The `Query` property uses the `Elastic.Clients.Elasticsearch.QueryDsl.Query` Elasticsearch type.
80
+
2. The `JsonConverter` attribute specifies the `RequestResponseConverter<T>` to be used for the `Query` property. This special converter instructs the `DefaultSourceSerializer` to delegate (de-)serialization to the `RequestResponseSerializer`.
81
+
82
+
::::{warning}
83
+
84
+
Failure to strictly use `RequestResponseConverter<T>` for `Elastic.Clients.Elasticsearch` types will most likely result in problems with document (de-)serialization.
The built-in source serializer handles most POCO document models correctly. Sometimes, you may need further control over how your types are serialized.
@@ -348,14 +382,17 @@ var client = new ElasticsearchClient(settings);
348
382
349
383
1. If implementing `Serializer` is enough, why must we provide an instance wrapped in a factory `Func`?
350
384
351
-
There are various cases where you might have a POCO type that contains an `Elastic.Clients.Elasticsearch` type as one of its properties. The `SourceSerializerFactory` delegate provides access to the default built-in serializer so you can access it when necessary. For example, consider if you want to use percolation; you need to store {{es}} queries as part of the `_source` of your document, which means you need to have a POCO that looks like this.
385
+
There are various cases where you might have a POCO type that contains an `Elastic.Clients.Elasticsearch` type as one of its properties (see [Elasticsearch types in documents](#elasticsearch-types-in-documents)). The `SourceSerializerFactory` delegate provides access to the default built-in serializer so you can access it when necessary. For example, consider if you want to use percolation; you need to store {{es}} queries as part of the `_source` of your document, which means you need to have a POCO that looks like this.
0 commit comments