parent-id-query.asciidoc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. PUT /my_index
  8. {
  9. "parent_id" : {
  10. "type" : "blog_tag",
  11. "id" : "1"
  12. }
  13. }
  14. --------------------------------------------------
  15. // CONSOLE
  16. // TESTSETUP
  17. The above is functionally equivalent to using the following
  18. <<query-dsl-has-parent-query, `has_parent`>> query, but performs
  19. better as it does not need to do a join:
  20. [source,js]
  21. --------------------------------------------------
  22. GET /_search
  23. {
  24. "query": {
  25. "has_parent": {
  26. "type": "blog",
  27. "query": {
  28. "term": {
  29. "_id": "1"
  30. }
  31. }
  32. }
  33. }
  34. }
  35. --------------------------------------------------
  36. // CONSOLE
  37. ==== Parameters
  38. This query has two required parameters:
  39. [horizontal]
  40. `type`:: The **child** type. This must be a type with `_parent` field.
  41. `id`:: The required parent id select documents must referrer to.
  42. `ignore_unmapped`:: When set to `true` this will ignore an unmapped `type` and will not match any
  43. documents for this query. This can be useful when querying multiple indexes
  44. which might have different mappings. When set to `false` (the default value)
  45. the query will throw an exception if the `type` is not mapped.