# Average size of documents in ElasticSearch

**URL:** <https://discuss.elastic.co/t/average-size-of-documents-in-elasticsearch/44464>\
**Category:** Elasticsearch\
**Created:** [March 15, 2016, 5:26pm UTC](https://discuss.elastic.co/t/average-size-of-documents-in-elasticsearch/44464 "2016-03-15T17:26:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cterron](https://avatars.discourse-cdn.com/v4/letter/c/ccd318/32.png) [@cterron](https://discuss.elastic.co/u/cterron)\
**Post date:** [March 15, 2016, 5:26pm UTC](https://discuss.elastic.co/t/average-size-of-documents-in-elasticsearch/44464/1 "2016-03-15T17:26:18Z")

</div>

Can I use a query like that to calculate the average size of documents in indexes if I don't have the \_size enable at index level but I have the \_source enabled?

```json
{
  "query" : {"match_all" : {}},
  "aggs":{
    "avg_length" : { "avg" : { "script" : "_source.toString().length()"}}
  }
}

```

Act  
Well, this is the char count. If strings are UTF-8 a think I can get the byte count with

```auto

  "query" : {"match_all" : {}},
  "aggs":{
    "avg_length" : { "avg" : { "script" : "_source.toString().getBytes(\"UTF-8\").length"}}
  }
}

```

Thanks

---

<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:** [July 5, 2017, 11:08pm UTC](https://discuss.elastic.co/t/average-size-of-documents-in-elasticsearch/44464/2 "2017-07-05T23:08:12Z")

</div>


