How to get source size using script?

I'm using Elasticsearch 1.3 and I need to return the source size in a query (I have _source enabled)

I tried with this query:

  "query": {
    "match_all" : {}
  "script_fields": {
    "source_size": {
      "script": "_source.toString().length()"

But source_size always returns 53.

Then I realized that _source.toString() returns the string ""

How can I get the json string so that I can get its size? Or any other script code to get the source size (in bytes or string length, I just need to find very big documents)?

The exact same code worked by using groovy as script lang

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