# How to find size of the document using scripting

**URL:** <https://discuss.elastic.co/t/how-to-find-size-of-the-document-using-scripting/174811>\
**Category:** Elasticsearch\
**Created:** [April 1, 2019, 3:37pm UTC](https://discuss.elastic.co/t/how-to-find-size-of-the-document-using-scripting/174811 "2019-04-01T15:37:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Riddhesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/riddhesh/32/47232_2.png) [@Riddhesh](https://discuss.elastic.co/u/Riddhesh)\
**Post date:** [April 1, 2019, 3:37pm UTC](https://discuss.elastic.co/t/how-to-find-size-of-the-document-using-scripting/174811/1 "2019-04-01T15:37:30Z")

</div>

I'm using ES 6.3, I want to find size of a document using script.  
I've tried:  
`"script": "doc.toString().length()"`  
But doc.toString() is classname `org.elasticsearch.search.lookup.LeafDocLookup@57b1c349`.

I know I can enable \_size by using size-mapper plugin, but don't have access to that, but scripting is enabled, so how can I do this?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 2, 2019, 10:47am UTC](https://discuss.elastic.co/t/how-to-find-size-of-the-document-using-scripting/174811/2 "2019-04-02T10:47:52Z")

</div>

Can you explain, what you are trying to achieve? You could try using a script ingest processor and just take the length of the `toString()` representation of the ctx map, however this would not be accurate, as it is not the original JSON.

Interested in the use-case here.

--Alex

---

<div class="post-metadata">

**Author:** ![Riddhesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/riddhesh/32/47232_2.png) [@Riddhesh](https://discuss.elastic.co/u/Riddhesh)\
**Post date:** [April 2, 2019, 11:04am UTC](https://discuss.elastic.co/t/how-to-find-size-of-the-document-using-scripting/174811/3 "2019-04-02T11:04:51Z")

</div>

@spinscale, I want to know total size of raw documents per day in the index. If I had the \_size enabled I would do search query like:

```
{
  "size": 0,
  "aggs" : {
    "size_per_day" : {
        "date_histogram" : {
            "field" : "@timestamp",
            "interval" : "day"
        },
        "aggs": {
            "size": {
                "sum": {
                    "field": "_size" # Want to use script to find size
                }
            }
        }
    }
  }
}

```

Also I can't use index stats as it will have the compressed size. Please let me know If there is any other way.

Thanks,  
RIddhesh

---

<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:** [April 30, 2019, 11:05am UTC](https://discuss.elastic.co/t/how-to-find-size-of-the-document-using-scripting/174811/4 "2019-04-30T11:05:02Z")

</div>

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