parent-id-query.asciidoc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. [[query-dsl-parent-id-query]]
  2. === Parent Id Query
  3. added[5.0.0]
  4. The `parent_id` query can be used to find child documents which belong to a particular parent:
  5. [source,js]
  6. --------------------------------------------------
  7. {
  8. "parent_id" : {
  9. "type" : "blog_tag",
  10. "id" : "1"
  11. }
  12. }
  13. --------------------------------------------------
  14. The above is functionally equivalent to using the following
  15. <<query-dsl-has-parent-query, `has_parent`>> query, but performs
  16. better as it does not need to do a join:
  17. [source,js]
  18. --------------------------------------------------
  19. {
  20. "has_parent": {
  21. "type": "blog",
  22. "query": {
  23. "term": {
  24. "_id": "1"
  25. }
  26. }
  27. }
  28. }
  29. --------------------------------------------------
  30. ==== Parameters
  31. This query has two required parameters:
  32. [horizontal]
  33. `type`:: The **child** type. This must be a type with `_parent` field.
  34. `id`:: The required parent id select documents must referrer to.
  35. `ignore_unmapped`:: When set to `true` this will ignore an unmapped `type` and will not match any
  36. documents for this query. This can be useful when querying multiple indexes
  37. which might have different mappings. When set to `false` (the default value)
  38. the query will throw an exception if the `type` is not mapped.