has-child-query.asciidoc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. [[query-dsl-has-child-query]]
  2. === Has Child Query
  3. The `has_child` filter accepts a query and the child type to run against, and
  4. results in parent documents that have child docs matching the query. Here is
  5. an example:
  6. [source,js]
  7. --------------------------------------------------
  8. {
  9. "has_child" : {
  10. "type" : "blog_tag",
  11. "query" : {
  12. "term" : {
  13. "tag" : "something"
  14. }
  15. }
  16. }
  17. }
  18. --------------------------------------------------
  19. [float]
  20. ==== Scoring capabilities
  21. The `has_child` also has scoring support. The
  22. supported score modes are `min`, `max`, `sum`, `avg` or `none`. The default is
  23. `none` and yields the same behaviour as in previous versions. If the
  24. score mode is set to another value than `none`, the scores of all the
  25. matching child documents are aggregated into the associated parent
  26. documents. The score type can be specified with the `score_mode` field
  27. inside the `has_child` query:
  28. [source,js]
  29. --------------------------------------------------
  30. {
  31. "has_child" : {
  32. "type" : "blog_tag",
  33. "score_mode" : "min",
  34. "query" : {
  35. "term" : {
  36. "tag" : "something"
  37. }
  38. }
  39. }
  40. }
  41. --------------------------------------------------
  42. [float]
  43. ==== Min/Max Children
  44. The `has_child` query allows you to specify that a minimum and/or maximum
  45. number of children are required to match for the parent doc to be considered
  46. a match:
  47. [source,js]
  48. --------------------------------------------------
  49. {
  50. "has_child" : {
  51. "type" : "blog_tag",
  52. "score_mode" : "min",
  53. "min_children": 2, <1>
  54. "max_children": 10, <1>
  55. "query" : {
  56. "term" : {
  57. "tag" : "something"
  58. }
  59. }
  60. }
  61. }
  62. --------------------------------------------------
  63. <1> Both `min_children` and `max_children` are optional.
  64. The `min_children` and `max_children` parameters can be combined with
  65. the `score_mode` parameter.
  66. [float]
  67. ==== Ignore Unmapped
  68. When set to `true` the `ignore_unmapped` option will ignore an unmapped `type`
  69. and will not match any documents for this query. This can be useful when
  70. querying multiple indexes which might have different mappings. When set to
  71. `false` (the default value) the query will throw an exception if the `type`
  72. is not mapped.