has-parent-query.asciidoc 2.1 KB

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