# How to get source size using script?

**URL:** <https://discuss.elastic.co/t/how-to-get-source-size-using-script/82038>\
**Category:** Elasticsearch\
**Created:** [April 11, 2017, 6:39pm UTC](https://discuss.elastic.co/t/how-to-get-source-size-using-script/82038 "2017-04-11T18:39:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RogerCF](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@RogerCF](https://discuss.elastic.co/u/RogerCF)\
**Post date:** [April 11, 2017, 6:39pm UTC](https://discuss.elastic.co/t/how-to-get-source-size-using-script/82038/1 "2017-04-11T18:39:50Z")

</div>

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 "org.elasticsearch.search.lookup.SourceLookup@30e2f99b"

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)?

---

<div class="post-metadata">

**Author:** ![RogerCF](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@RogerCF](https://discuss.elastic.co/u/RogerCF)\
**Post date:** [April 12, 2017, 11:31pm UTC](https://discuss.elastic.co/t/how-to-get-source-size-using-script/82038/2 "2017-04-12T23:31:14Z")

</div>

The exact same code worked by using groovy as script lang

---

<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:** [May 10, 2017, 11:37pm UTC](https://discuss.elastic.co/t/how-to-get-source-size-using-script/82038/3 "2017-05-10T23:37:33Z")

</div>

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