# How to get text field size

**URL:** <https://discuss.elastic.co/t/how-to-get-text-field-size/290350>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [November 28, 2021, 12:39am UTC](https://discuss.elastic.co/t/how-to-get-text-field-size/290350 "2021-11-28T00:39:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liangliang\_Qiu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/liangliang_qiu/32/78183_2.png) [@Liangliang\_Qiu](https://discuss.elastic.co/u/Liangliang_Qiu)\
**Post date:** [November 28, 2021, 12:39am UTC](https://discuss.elastic.co/t/how-to-get-text-field-size/290350/1 "2021-11-28T00:39:31Z")

</div>

when i run this script :

```auto

GET shopee_smart_sorting_my_db__address_match_result_tab*/_search
{
  "script_fields": {
    "full_name": {
      "script": {
        "lang": "painless",
        "source": """
          if (params._source['final_hub_zone_id'].empty)
          {
            return 0
          }
          else{
            return params._source['final_hub_zone_id']
          }
          """
      }
    }
  }
}

```

it shows,

```auto
{
  "took" : 22,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "shopee_smart_sorting_my_db__address_match_result_tab-2021.11-000001",
        "_type" : "_doc",
        "_id" : "vU1IYH0BwXKUDArCmCLN",
        "_score" : 1.0,
        "fields" : {
          "full_name" : [
            0
          ]
        }
      },
      {
        "_index" : "shopee_smart_sorting_my_db__address_match_result_tab-2021.11-000001",
        "_type" : "_doc",
        "_id" : "vk1IYH0BwXKUDArCmCLN",
        "_score" : 1.0,
        "fields" : {
          "full_name" : [
            "A-CJY-Z1"
          ]
        }
      }
}

```

but i want to get the new filed's size, how to get it?  
is there any easier way?

---

<div class="post-metadata">

**Author:** ![Liangliang\_Qiu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/liangliang_qiu/32/78183_2.png) [@Liangliang\_Qiu](https://discuss.elastic.co/u/Liangliang_Qiu)\
**Post date:** [November 29, 2021, 11:50am UTC](https://discuss.elastic.co/t/how-to-get-text-field-size/290350/2 "2021-11-29T11:50:17Z")

</div>

solved it by myself.

```auto
{
  "script_fields": {
    "final_hub_zone_id_len": {
      "script": {
        "lang": "painless",
        "source": "params._source['final_hub_zone_id'].toString().length()"
      }
    }
  }
}

```

---

<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:** [December 27, 2021, 11:50am UTC](https://discuss.elastic.co/t/how-to-get-text-field-size/290350/3 "2021-12-27T11:50:31Z")

</div>

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