2013-08-28 19:24:34 -04:00
[[mapping-parent-field]]
=== `_parent`
2015-03-25 05:42:49 -04:00
TIP: It is highly recommend to reindex all indices with `_parent` field created before version 2.x.
The reason for this is to gain from all the optimizations added with the 2.0 release.
2013-08-28 19:24:34 -04:00
The parent field mapping is defined on a child mapping, and points to
the parent type this child relates to. For example, in case of a `blog`
type and a `blog_tag` type child document, the mapping for `blog_tag`
should be:
[source,js]
--------------------------------------------------
{
"blog_tag" : {
"_parent" : {
"type" : "blog"
}
}
}
--------------------------------------------------
The mapping is automatically stored and indexed (meaning it can be
searched on using the `_parent` field notation).
2015-02-22 17:15:37 -05:00
2015-03-25 05:42:49 -04:00
==== Limitations
The `_parent.type` setting can only point to a type that doesn't exist yet.
This means that a type can't become a parent type after is has been created.
The `parent.type` setting can't point to itself. This means self referential
parent/child isn't supported.
==== Global ordinals
2015-05-29 16:45:01 -04:00
Parent-child uses <<global-ordinals,global ordinals>> to speed up joins and global ordinals need to be rebuilt after any change to a shard.
2015-03-25 05:42:49 -04:00
The more parent id values are stored in a shard, the longer it takes to rebuild global ordinals for the `_parent` field.
Global ordinals, by default, are built lazily: the first parent-child query or aggregation after a refresh will trigger building of global ordinals.
2015-05-29 16:45:01 -04:00
This can introduce a significant latency spike for your users. You can use <<fielddata-loading,eager_global_ordinals>> to shift the cost of building global ordinals
2015-03-25 05:42:49 -04:00
from query time to refresh time, by mapping the _parent field as follows:
2015-02-22 17:15:37 -05:00
2015-03-25 05:42:49 -04:00
==== Memory usage
The only on heap memory used by parent/child is the global ordinals for the `_parent` field.
How much memory is used for the global ordianls for the `_parent` field in the fielddata cache
can be checked via the <<indices-stats,indices stats>> or <<cluster-nodes-stats,nodes stats>>
APIS, eg:
[source,js]
--------------------------------------------------
curl -XGET "http://localhost:9200/_stats/fielddata?pretty&human&fielddata_fields=_parent"
--------------------------------------------------