How to get text field size

when i run this script :


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,

{
  "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?

solved it by myself.

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

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