has-parent-query.asciidoc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. [[query-dsl-has-parent-query]]
  2. == Has Parent Query
  3. The `has_parent` query accepts a query and a parent type. The query is
  4. executed in the parent document space, which is specified by the parent
  5. type. This query returns child documents which associated parents have
  6. matched. For the rest `has_parent` query has the same options and works
  7. in the same manner as the `has_child` query.
  8. [source,js]
  9. --------------------------------------------------
  10. {
  11. "has_parent" : {
  12. "parent_type" : "blog",
  13. "query" : {
  14. "term" : {
  15. "tag" : "something"
  16. }
  17. }
  18. }
  19. }
  20. --------------------------------------------------
  21. [float]
  22. === Scoring capabilities
  23. The `has_parent` also has scoring support. The
  24. supported score types are `score` or `none`. The default is `none` and
  25. this ignores the score from the parent document. The score is in this
  26. case equal to the boost on the `has_parent` query (Defaults to 1). If
  27. the score type is set to `score`, then the score of the matching parent
  28. document is aggregated into the child documents belonging to the
  29. matching parent document. The score type can be specified with the
  30. `score_mode` field inside the `has_parent` query:
  31. [source,js]
  32. --------------------------------------------------
  33. {
  34. "has_parent" : {
  35. "parent_type" : "blog",
  36. "score_mode" : "score",
  37. "query" : {
  38. "term" : {
  39. "tag" : "something"
  40. }
  41. }
  42. }
  43. }
  44. --------------------------------------------------
  45. [float]
  46. === Memory Considerations
  47. In order to support parent-child joins, all of the (string) parent IDs
  48. must be resident in memory (in the <<index-modules-fielddata,field data cache>>.
  49. Additionally, every child document is mapped to its parent using a long
  50. value (approximately). It is advisable to keep the string parent ID short
  51. in order to reduce memory usage.
  52. You can check how much memory is being used by the ID cache using the
  53. <<indices-stats,indices stats>> or <<cluster-nodes-stats,nodes stats>>
  54. APIS, eg:
  55. [source,js]
  56. --------------------------------------------------
  57. curl -XGET "http://localhost:9200/_stats/id_cache?pretty&human"
  58. --------------------------------------------------