# How to calculate the total document length

**URL:** <https://discuss.elastic.co/t/how-to-calculate-the-total-document-length/137164>\
**Category:** Elasticsearch\
**Created:** [June 24, 2018, 7:02pm UTC](https://discuss.elastic.co/t/how-to-calculate-the-total-document-length/137164 "2018-06-24T19:02:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![atef](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/atef/32/51937_2.png) [@atef](https://discuss.elastic.co/u/atef)\
**Post date:** [June 24, 2018, 7:02pm UTC](https://discuss.elastic.co/t/how-to-calculate-the-total-document-length/137164/1 "2018-06-24T19:02:14Z")

</div>

please is there anyone know how to calculate the total document length (number of characters)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 24, 2018, 7:13pm UTC](https://discuss.elastic.co/t/how-to-calculate-the-total-document-length/137164/2 "2018-06-24T19:13:35Z")

</div>

You need to compute that at index time.  
The mapper size plugin might help.

---

<div class="post-metadata">

**Author:** ![atef](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/atef/32/51937_2.png) [@atef](https://discuss.elastic.co/u/atef)\
**Post date:** [June 24, 2018, 8:41pm UTC](https://discuss.elastic.co/t/how-to-calculate-the-total-document-length/137164/3 "2018-06-24T20:41:42Z")

</div>

are you know why when i try to enable \_size field

```
PUT category
{
  "mappings": {
    "cat": {
      "_size": {
        "enabled": true
      }
    }
  }
}

```

i got this error

```
{
  "error": {
    "root_cause": [
      {
        "type": "resource_already_exists_exception",
        "reason": "index [category/oDbxbu8nR42ieKtKSRZdZQ] already exists",
        "index_uuid": "oDbxbu8nR42ieKtKSRZdZQ",
        "index": "category"
      }
    ],
    "type": "resource_already_exists_exception",
    "reason": "index [category/oDbxbu8nR42ieKtKSRZdZQ] already exists",
    "`index_uuid`": "oDbxbu8nR42ieKtKSRZdZQ",
    "index": "category"
  },
  "status": 400
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 25, 2018, 2:29am UTC](https://discuss.elastic.co/t/how-to-calculate-the-total-document-length/137164/4 "2018-06-25T02:29:04Z")

</div>

I believe you need to create a new index and reindex.

---

<div class="post-metadata">

**Author:** ![paulkeogh](https://avatars.discourse-cdn.com/v4/letter/p/8dc957/32.png) [@paulkeogh](https://discuss.elastic.co/u/paulkeogh)\
**Post date:** [June 25, 2018, 10:21am UTC](https://discuss.elastic.co/t/how-to-calculate-the-total-document-length/137164/5 "2018-06-25T10:21:39Z")

</div>

Do you is it possible to display the \_size ? The docs say that it can be used for querying, aggregating, sorting etc but I can't find any way to access it in a view.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 25, 2018, 1:47pm UTC](https://discuss.elastic.co/t/how-to-calculate-the-total-document-length/137164/6 "2018-06-25T13:47:06Z")

</div>

Try this: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-docvalue-fields.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-docvalue-fields.html)

---

<div class="post-metadata">

**Author:** ![atef](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/atef/32/51937_2.png) [@atef](https://discuss.elastic.co/u/atef)\
**Post date:** [June 25, 2018, 1:55pm UTC](https://discuss.elastic.co/t/how-to-calculate-the-total-document-length/137164/7 "2018-06-25T13:55:30Z")

</div>

but me i looking to compute matching words to define a new score for a query (number(match\_word)/number(document\_word))

---

<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 23, 2018, 1:55pm UTC](https://discuss.elastic.co/t/how-to-calculate-the-total-document-length/137164/8 "2018-07-23T13:55:36Z")

</div>

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