parent-field.asciidoc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. [[mapping-parent-field]]
  2. === `_parent`
  3. TIP: It is highly recommend to reindex all indices with `_parent` field created before version 2.x.
  4. The reason for this is to gain from all the optimizations added with the 2.0 release.
  5. The parent field mapping is defined on a child mapping, and points to
  6. the parent type this child relates to. For example, in case of a `blog`
  7. type and a `blog_tag` type child document, the mapping for `blog_tag`
  8. should be:
  9. [source,js]
  10. --------------------------------------------------
  11. {
  12. "blog_tag" : {
  13. "_parent" : {
  14. "type" : "blog"
  15. }
  16. }
  17. }
  18. --------------------------------------------------
  19. The mapping is automatically stored and indexed (meaning it can be
  20. searched on using the `_parent` field notation).
  21. ==== Limitations
  22. The `_parent.type` setting can only point to a type that doesn't exist yet.
  23. This means that a type can't become a parent type after is has been created.
  24. The `parent.type` setting can't point to itself. This means self referential
  25. parent/child isn't supported.
  26. ==== Global ordinals
  27. Parent-child uses <<global-ordinals,global ordinals>> to speed up joins and global ordinals need to be rebuilt after any change to a shard.
  28. The more parent id values are stored in a shard, the longer it takes to rebuild global ordinals for the `_parent` field.
  29. Global ordinals, by default, are built lazily: the first parent-child query or aggregation after a refresh will trigger building of global ordinals.
  30. 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
  31. from query time to refresh time, by mapping the _parent field as follows:
  32. ==== Memory usage
  33. The only on heap memory used by parent/child is the global ordinals for the `_parent` field.
  34. How much memory is used for the global ordianls for the `_parent` field in the fielddata cache
  35. can be checked via the <<indices-stats,indices stats>> or <<cluster-nodes-stats,nodes stats>>
  36. APIS, eg:
  37. [source,js]
  38. --------------------------------------------------
  39. curl -XGET "http://localhost:9200/_stats/fielddata?pretty&human&fielddata_fields=_parent"
  40. --------------------------------------------------