--- title: About the parentId property slug: '57' canonical_url: https://docs.coveo.com/en/57/ collection: index-content source_format: adoc --- # About the parentId property When adding or updating [items](https://docs.coveo.com/en/210/) in a Push [source](https://docs.coveo.com/en/246/), you can use the `parentId` property to [define parent-child relationships](#define-parent-child-relationships) between those items. Doing so populates a set of [fields](https://docs.coveo.com/en/200/) that you can [leverage in nested queries](#leverage-parentid-generated-fields-in-nested-queries). > **Note** > > Using the `parentId` property doesn't populate any field that would allow you to load the parent of a folded collection. > > Therefore, to [request and render folded results](https://docs.coveo.com/en/428/) from a Push source, you should rather define your parent-child relationships by sending metadata to populate the [standard folding fields](https://docs.coveo.com/en/2718/) in your index (that is, `@foldingcollection`, `@foldingparent`, and `@foldingchild`). ## Define parent-child relationships You can use the `parentId` property to define simple parent-child relationships between items in a Push source. To do so: * If an item is the _parent_ of a relationship, set its `parentId` to its own `documentId`. * If an item is a _child_ in a relationship, set its `parentId` to the `documentId` of its parent. Specifying a `parentId` when pushing an item always populates the `@topparentid` field for that item. If the `parentId` value differs from the `documentId` value of the pushed item, the `@attachmentparentid` field gets populated as well. ### Example In a Push source, you want to define simple parent-child relationships between items representing directors and movies. . You [create a file container](https://docs.coveo.com/en/43/). ```http POST https://api.cloud.coveo.com/push/v1/organizations/coveomovieorganization/files HTTP/1.1 ​ Authorization: Bearer **********-****-****-****-************ Accept: application/json ``` . You [upload a batch of items into the file container](https://docs.coveo.com/en/90#step-2-upload-the-content-update-into-the-file-container) you previously created, using the `parentId` property to define the desired relationships. ```http PUT https://coveo-nprod-customerdata.s3.amazonaws.com/proda/blobstore/coveomovieorganization/2a65f989-2371-4dc6-b6aa-198b5b88ff29?x-amz-security-token=FQoGZXIvYXdzEB8aDL37SykFY6%2FzbYBDPCLlAQmJ0nWbMK0Bxq3wcGnEq1bPcDGsP7dTaKkuuAPOA7LaNZhosW3d8ybg14N8o9OAaUS%2BoQ9Y1oZROmh%2BHZbP7krJAlDRUQS2NtrGxUh20h3GInWxTM5CZ86p5een1Gzsk%2FuCrKCXpqGFJZ1UwEFkEGtj2M2l%2F3eOhfPd6ga9%2F51NgHQPXRc4z%2F5NLiEfWlv%2FxzLZHrtznCjj8fi77QKcLkzO9kiLOtWtZVxmoMg4jVZYwZuOdfRqAVEzaWIsP8lQ2O5AWTwD5O8HKjmtO6v%2FZiV9diYDx7Z7WtrKJg1v2upFHhxljxUo6%2BCG2wU%3D&AWSAccessKeyId=ASIAYKDJLZIT5VRAMAJE&Expires=1533134515&Signature=fyZW7rDLYWSt%2B6rRTPaQPc72uUY%3D HTTP/1.1 ​ Content-Type: application/octet-stream x-amz-server-side-encryption: "AES256" ``` Request body: ```json { "addOrUpdate": [ { "title": "Edgar Wright", "data": "...", "documentId": "file://directors/edgar-wright.txt", "parentId": "file://directors/edgar-wright.txt", "documenttype": "Director" }, { "title": "The World's End", "data": "...", "documentId": "file://movies/the-world-s-end.txt", "parentId": "file://directors/edgar-wright.txt", "documenttype": "Movie" }, { "title": "Baby Driver", "data": "...", "documentId": "file://movies/baby-driver.txt", "parentId": "file://directors/edgar-wright.txt", "documenttype": "Movie" }, { "title": "Stanley Kubrick", "data": "...", "documentId": "file://directors/stanley-kubrick.txt", "parentId": "file://directors/stanley-kubrick.txt", "documenttype": "Director" }, { "title": "The Shining", "data": "...", "documentId": "file://movies/the-shining.txt", "parentId": "file://directors/stanley-kubrick.txt", "documenttype": "Movie" } ], "delete": [] } ``` . You [push the file container](https://docs.coveo.com/en/90#step-3-push-the-file-container-into-a-push-source) to your source. ```http POST https://api.cloud.coveo.com/push/v1/organizations/coveomovieorganization/sources/vzievcixq66qq5q6xulpy32dqi-coveomovieorganization/documents/batch?fileId=b5e8767e-8f0d-4a89-9095-1127915c89c7 HTTP/1.1 ​ Authorization: Bearer **********-****-****-****-************ Accept: application/json ``` When the indexing pipeline finishes processing the batch, the `@topparentid` and `@attachmentparentid` fields are populated as follows: |=== | Item title | Document type | `@topparentid` value | `@attachmentparentid` value | Edgar Wright | Director | 32345 | N/A | Stanley Kubrick | Director | 32338 | N/A | The World's End | Movie | 32345 | 32345 | Baby Driver | Movie | 32345 | 32345 | The Shining | Movie | 32338 | 32338 |=== ## Leverage parentId-generated fields in nested queries The `@topparentid` and `@attachmentparentid` numeric fields can be useful in [nested queries](https://docs.coveo.com/en/220/). > **Leading practice** > > Ensure that the [**Use cache for numeric queries** option](https://docs.coveo.com/en/1833#use-cache-for-nested-queries) is enabled for nested query fields. > Doing so will allow for quicker numeric operations (for example, comparing integers), making query executions faster. ### Example When querying items from the Push source described in the [Defining parent-child relationships](#define-parent-child-relationships) example, you could use the following nested query to retrieve all movies by director Edgar Wright: ```text [[@attachmentparentid] @topparentid==32345] ``` **Query response excerpt** ```json { "totalCount": 2, ... "results": [ { "title": "Baby Driver", "uri": "file://movies/baby-driver.txt", ... "raw": { ... "attachmentparentid": 32345, "topparentid": 32345, ... } ... }, { "title": "The World's End", "uri": "file://movies/the-world-s-end.txt", ... "raw": { ... "attachmentparentid": 32345, "topparentid": 32345, ... } ... } ] } ```