# Scripting access other documents fields of result

**URL:** <https://discuss.elastic.co/t/scripting-access-other-documents-fields-of-result/119662>\
**Category:** Elasticsearch\
**Created:** [February 13, 2018, 3:04pm UTC](https://discuss.elastic.co/t/scripting-access-other-documents-fields-of-result/119662 "2018-02-13T15:04:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mstkk](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@mstkk](https://discuss.elastic.co/u/mstkk)\
**Post date:** [February 13, 2018, 3:04pm UTC](https://discuss.elastic.co/t/scripting-access-other-documents-fields-of-result/119662/1 "2018-02-13T15:04:29Z")

</div>

```
GET /_search
{
     "_source": "classified_id", 
  "query": {
    "bool": {
      "filter": {
        "term": {
          "town.areaId.keyword": "134"
        }
      }
    }
  },
  "script_fields": {
     "test2": {
      "script": {
        "source": "doc['user.id'].value == doc['user.id'].value"
      }
    }
  },
  "size": 10
}

```

I have query like this i want to count same user.id field values in results but i can only access doc itself.  
Can i reach other documents of results is that possible ?

I just want to count user.id and sorting it for every user when i have the result

if one user have 5 products  
first product of X user have scripted field values 1  
second product of X user have scripted field values 2  
third product of X user have scripted field values 3

first product of Y user have scripted field values 1  
second product of Y user have scripted field values 2

and then sort by that scripted field.. is that possible by elasticsearch ?

---

<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:** [March 13, 2018, 3:05pm UTC](https://discuss.elastic.co/t/scripting-access-other-documents-fields-of-result/119662/2 "2018-03-13T15:05:03Z")

</div>

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