Access to inner_hits from painless script during sorting

I am using nested query in Elasticsearch search query. Something like this:
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"bool": {
"should": [
{
"match": {
"id": {
"query": "department1"
}
}
},
{
"match": {
"id": {
"query": "company1"
}
}
}
]
}
}
]
}
},
{
"bool": {
"should": [
{
"bool": {
"should": [
{
"nested" : {
"path" : "peoples",
"ignore_unmapped" : "true",
"query" : {
"bool" : {
"must" : [
{
"match" : {
"peoples.firstName" : "firstName12"
}
}
]
}
},
"inner_hits": { }
}
},
{
"nested" : {
"path" : "entities",
"ignore_unmapped" : "true",
"query" : {
"bool" : {
"must" : [
{
"match" : {
"entities.firstName" : "firstName13"
}
}
]
}
},
"inner_hits": { }
}
}
]
}
}
]
}
}
]
}
}

And then I want to access to inner_hits data from sorting script:

  "sort": [
    {
      "_script": {
        "type": "string",
        "order": "asc",
        "script": {
          "lang": "painless",
          "inline": "**inner_hits**"
        }
      }
    }
  ]

Is it possible?

It is not possible, in any scripting language (not just painless). Inner hits are completely separate documents within lucene, but scripts operate on a single document at a time.

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