-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds some basic docs for synthetic source both to get us started documenting it and to show how I'd like to get it documented - with a central section in the docs for `_source` and "satellite" sections in each of the supported field types that link back to the central section. [Preview](https://elasticsearch_87416.docs-preview.app.elstc.co/guide/en/elasticsearch/reference/master/mapping-source-field.html#synthetic-source)
- Loading branch information
Showing
8 changed files
with
419 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
docs/reference/mapping/fields/synthetic-source.asciidoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
[[synthetic-source]] | ||
==== Synthetic `_source` | ||
|
||
Though very handy to have around, the source field takes up a significant amount | ||
of space on disk. Instead of storing source documents on disk exactly as you | ||
send them, Elasticsearch can reconstruct source content on the fly upon retrieval. | ||
Enable this by setting `synthetic: true` in `_source`: | ||
|
||
[source,console,id=enable-synthetic-source-example] | ||
---- | ||
PUT idx | ||
{ | ||
"mappings": { | ||
"_source": { | ||
"synthetic": true | ||
} | ||
} | ||
} | ||
---- | ||
// TESTSETUP | ||
|
||
While this on the fly reconstruction is *generally* slower than saving the source | ||
documents verbatim and loading them at query time, it saves a lot of storage | ||
space. There are a couple of restrictions to be aware of: | ||
|
||
* When you retrieve synthetic `_source` content it undergoes minor | ||
<<synthetic-source-modifications,modifications>> compared to the original JSON. | ||
* Synthetic `_source` can be used with indices that contain only these field | ||
types: | ||
|
||
** <<boolean-synthetic-source,`boolean`>> | ||
** <<numeric-synthetic-source,`byte`>> | ||
** <<numeric-synthetic-source,`double`>> | ||
** <<numeric-synthetic-source,`float`>> | ||
** <<geo-point-synthetic-source,`geo_point`>> | ||
** <<numeric-synthetic-source,`half_float`>> | ||
** <<numeric-synthetic-source,`integer`>> | ||
** <<ip-synthetic-source,`ip`>> | ||
** <<keyword-synthetic-source,`keyword`>> | ||
** <<numeric-synthetic-source,`long`>> | ||
** <<numeric-synthetic-source,`scaled_float`>> | ||
** <<numeric-synthetic-source,`short`>> | ||
** <<text-synthetic-source,`text`>> (with a `keyword` sub-field) | ||
|
||
[[synthetic-source-modifications]] | ||
===== Synthetic source modifications | ||
|
||
When synthetic `_source` is enabled, retrieved documents undergo some | ||
modifications compared to the original JSON. | ||
|
||
[[synthetic-source-modifications-leaf-arrays]] | ||
====== Arrays moved to leaf fields | ||
Synthetic `_source` arrays are moved to leaves. For example: | ||
|
||
[source,console,id=synthetic-source-leaf-arrays-example] | ||
---- | ||
PUT idx/_doc/1 | ||
{ | ||
"foo": [ | ||
{ | ||
"bar": 1 | ||
}, | ||
{ | ||
"bar": 2 | ||
} | ||
] | ||
} | ||
---- | ||
// TEST[s/$/\nGET idx\/_doc\/1?filter_path=_source\n/] | ||
|
||
Will become: | ||
|
||
[source,console-result] | ||
---- | ||
{ | ||
"foo": { | ||
"bar": [1, 2] | ||
} | ||
} | ||
---- | ||
// TEST[s/^/{"_source":/ s/\n$/}/] | ||
|
||
[[synthetic-source-modifications-field-names]] | ||
====== Fields named as they are mapped | ||
Synthetic source names fields as they are named in the mapping. When used | ||
with <<dynamic,dynamic mapping>>, fields with dots (`.`) in their names are, by | ||
default, interpreted as multiple objects, while dots in field names are | ||
preserved within objects that have <<subobjects>> disabled. For example: | ||
|
||
[source,console,id=synthetic-source-objecty-example] | ||
---- | ||
PUT idx/_doc/1 | ||
{ | ||
"foo.bar.baz": 1 | ||
} | ||
---- | ||
// TEST[s/$/\nGET idx\/_doc\/1?filter_path=_source\n/] | ||
|
||
Will become: | ||
|
||
[source,console-result] | ||
---- | ||
{ | ||
"foo": { | ||
"bar": { | ||
"baz": 1 | ||
} | ||
} | ||
} | ||
---- | ||
// TEST[s/^/{"_source":/ s/\n$/}/] | ||
|
||
[[synthetic-source-modifications-alphabetical]] | ||
====== Alphabetical sorting | ||
Synthetic `_source` fields are sorted alphabetically. The | ||
https://www.rfc-editor.org/rfc/rfc7159.html[JSON RFC] defines objects as | ||
"an unordered collection of zero or more name/value pairs" so applications | ||
shouldn't care but without synthetic `_source` the original ordering is | ||
preserved and some applications may, counter to the spec, do something with | ||
that ordering. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.