Scripting access other documents fields of result

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 ?

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