# Get doc \_parent value in sort script

**URL:** <https://discuss.elastic.co/t/get-doc--parent-value-in-sort-script/101688>\
**Category:** Elasticsearch\
**Created:** [September 25, 2017, 11:26am UTC](https://discuss.elastic.co/t/get-doc--parent-value-in-sort-script/101688 "2017-09-25T11:26:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anton\_Dzemuh](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@Anton\_Dzemuh](https://discuss.elastic.co/u/Anton_Dzemuh)\
**Post date:** [September 25, 2017, 11:26am UTC](https://discuss.elastic.co/t/get-doc--parent-value-in-sort-script/101688/1 "2017-09-25T11:26:15Z")

</div>

I have parent/child relation, and i want to access to \_parent field in sort script.  
It is possible?

```
    It's body on php
        
    'body' => [
        'from' => $offset,
        'size' => $size,
        'sort' => [
            '_script' => [
                'script' => 'doc._parent', - how can i get _parent value of document?
                'type' => 'number',
                'order' => 'desc'
            ]
        ],
        'query' => some query
    ]
    
    Thanks
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 23, 2017, 11:26am UTC](https://discuss.elastic.co/t/get-doc--parent-value-in-sort-script/101688/2 "2017-10-23T11:26:52Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
