0

In elasticsearch head I run query for retriving some aggregations. To do it, I need to get some infos from ctx variable. In my script when I try to use: ctx._source I get nullPointerException.

"aggregations": {
    "fieldId": {
      "terms": {
        "script": {
          "source": "... <Here I want to get ctx._source but I get null pointer>... ,
          "lang": "painless"
        },
        ...
        ]
      }
    }
  }

1 Answers1

0

The special ctx variables is only available during indexation ( ingest processor, update_by_query etc... ).

For more information about painless script context and available variable you can go here.

I don't think the source is available during aggregation since it would for elastic to all sources of documents before making the aggregations. That would have a huge overhead. You can only rely on doc_values to create the scripted value.

Pierre Mallet
  • 7,053
  • 2
  • 19
  • 30