has-child-query.asciidoc 2.6 KB

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