- Elasticsearch 7.0 Cookbook(Fourth Edition)
- Alberto Paro
- 180字
- 2021-06-24 14:52:05
How it works...
When a document is indexed, if an embedded object is marked as nested, it's extracted by the original document, before being and indexed in a new external document, saved in a special index position near the parent document.
In the preceding example, we reused the mapping of the Mapping an Object recipe, but we changed the type of the item from object to nested. No other required action must be taken to convert an embedded object into a nested one.
The nested objects are special Lucene documents that are saved in the same block of data of its parent—this approach allows for fast joining with the parent document.
Nested objects are not searchable with standard queries, only with nested ones. They are not shown in standard query results.
The lives of nested objects are related to their parents: deleting/updating a parent automatically deletes/updates all nested children. Changing the parent means Elasticsearch will do the following:
- Mark old documents as deleted
- Mark all nested documents as deleted
- Index the new document version
- Index all nested documents