# Inner hits and script score

**URL:** https://discuss.elastic.co/t/inner-hits-and-script-score/1970
**Category:** Elasticsearch
**Created:** [June 4, 2015, 9:51pm UTC](https://discuss.elastic.co/t/inner-hits-and-script-score/1970 "2015-06-04T21:51:39Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nicom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicom/32/488_2.png) [@nicom](https://discuss.elastic.co/u/nicom)
#### Post date: [June 4, 2015, 9:51pm UTC](https://discuss.elastic.co/t/inner-hits-and-script-score/1970/1 "2015-06-04T21:51:39Z")

</div>

i have a mapping structured a la "post with comments" = with nested object

let that that for each comment i have the number of like as property

post1 with comments : [{text:asd. likes:3), {text;asdadsa likes:3]  
post2 with comments : [{text:fdg. likes:4), {text;asdagf likes:1]  
post3 with comments : [{text:rwe. likes:1), {text;asda likes:1]

I would like to retrieve the N posts with comments being the most liked.

the resutls should be  
post 2  
post 1  
post 3

any guide to help me?

1. I would like to use as document score the number of like of the most liked comments of the post . How to do that?  
with ES and function score / script score? how to first access the fields of inner hits via a scripted score?

thanks a lot !

---

<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: [July 6, 2017, 12:09am UTC](https://discuss.elastic.co/t/inner-hits-and-script-score/1970/2 "2017-07-06T00:09:32Z")

</div>


