# How to change field-type in ELK from string to numeric/long?

**URL:** <https://discuss.elastic.co/t/how-to-change-field-type-in-elk-from-string-to-numeric-long/303665>\
**Category:** Kibana\
**Created:** [May 1, 2022, 11:47am UTC](https://discuss.elastic.co/t/how-to-change-field-type-in-elk-from-string-to-numeric-long/303665 "2022-05-01T11:47:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Next\_generation](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/next_generation/32/105074_2.png) [@Next\_generation](https://discuss.elastic.co/u/Next_generation)\
**Post date:** [May 1, 2022, 11:47am UTC](https://discuss.elastic.co/t/how-to-change-field-type-in-elk-from-string-to-numeric-long/303665/1 "2022-05-01T11:47:25Z")

</div>

For haproxy tc, tw, tr, tq are written in Type string but long

I created a new index (I took it from another index mapping) and in the Dev Tools ELK console I entered

 ![Снимок экрана 2022-05-01 в 14.12.55](https://us1.discourse-cdn.com/elastic/original/3X/b/2/b286a03c569db9c34cc7d75f684401bc0ed71e4c.png)

ELK verison: 7.16.2

How fix it? Thanks a lot

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 1, 2022, 11:30pm UTC](https://discuss.elastic.co/t/how-to-change-field-type-in-elk-from-string-to-numeric-long/303665/2 "2022-05-01T23:30:57Z")

</div>

Welcome to our community! 😃  
Please don't post pictures of text, logs or code. They are difficult to read, impossible to search and replicate (if it's code), and some people may not be even able to see them.

Generally for this sort of thing, you'd use a template rather than define it for a specific index. If you can share the mapping as code, we can make suggestions.

---

<div class="post-metadata">

**Author:** ![Next\_generation](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/next_generation/32/105074_2.png) [@Next\_generation](https://discuss.elastic.co/u/Next_generation)\
**Post date:** [May 2, 2022, 6:56am UTC](https://discuss.elastic.co/t/how-to-change-field-type-in-elk-from-string-to-numeric-long/303665/3 "2022-05-02T06:56:56Z")

</div>

Ok, sorry

It's example Mappings from working template. I don't understand how I put it to new index with change values(tc, tw, tr, tq, tt) from string to numeric :

```auto

{
  "mappings": {
    "_doc": {
      "properties": {
        "@timestamp": {
          "type": "date"
        },
        "actconn": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "b_end": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "b_server": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "backend_queue": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "beconn": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "bytes": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "c_ip": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "c_port": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "f_end": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "feconn": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "filename": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "message": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "pid": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "ps": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "req_cookie": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "req_headers": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "request": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "res_cookie": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "retries": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "srv_conn": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "srv_queue": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "status_code": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "syslog_host": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "syslog_time": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "t_state": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "tc": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "tq": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "tr": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "tt": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "tw": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 2, 2022, 7:19am UTC](https://discuss.elastic.co/t/how-to-change-field-type-in-elk-from-string-to-numeric-long/303665/4 "2022-05-02T07:19:26Z")

</div>

Thanks!

Generally you wouldn't have `text` and `keyword` values like that unless you are dealing with actual text. Numeric fields, like `bytes`, `pid` and so on should just be numeric. eg;

```auto
"bytes": {
  "type": "long",
},

```

This saves adding extra fields in your index, and will reduce resource overall utilisation.

Then you take that mapping, and run through [Index templates | Elasticsearch Guide [8.1] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/8.1/index-templates.html)

---

<div class="post-metadata">

**Author:** ![Next\_generation](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/next_generation/32/105074_2.png) [@Next\_generation](https://discuss.elastic.co/u/Next_generation)\
**Post date:** [May 2, 2022, 10:00am UTC](https://discuss.elastic.co/t/how-to-change-field-type-in-elk-from-string-to-numeric-long/303665/6 "2022-05-02T10:00:43Z")

</div>

You mean like this?

```auto
"tc": {
         "type": "long",
         "fields": {
            "bytes": {
              "type": "long",
              "ignore_above": 256
            }
          }
       }

```

and will there be a similar recording format for other mapping values?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 3, 2022, 12:22am UTC](https://discuss.elastic.co/t/how-to-change-field-type-in-elk-from-string-to-numeric-long/303665/7 "2022-05-03T00:22:51Z")

</div>

No, because you will end up with `tc` mapped as a long, and `tc.bytes` mapped as a long. remove the entire `fields` section.

---

<div class="post-metadata">

**Author:** ![Next\_generation](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/next_generation/32/105074_2.png) [@Next\_generation](https://discuss.elastic.co/u/Next_generation)\
**Post date:** [May 3, 2022, 8:49am UTC](https://discuss.elastic.co/t/how-to-change-field-type-in-elk-from-string-to-numeric-long/303665/8 "2022-05-03T08:49:56Z")

</div>

thanks for the tip  
I'm sorry, I'm trying but haven't got the desired result yet(

```auto
PUT /test-index-000002/_mapping/test
{
  "mappings": {
    "_doc": {
      "properties": {
        "@timestamp": {
          "type": "date"
        },
        "actconn": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "b_end": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "b_server": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "backend_queue": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "beconn": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "bytes": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "c_ip": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "c_port": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "f_end": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "feconn": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "filename": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "message": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "pid": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "ps": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "req_cookie": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "req_headers": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "request": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "res_cookie": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "retries": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "srv_conn": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "srv_queue": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "status_code": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "syslog_host": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "syslog_time": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "t_state": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
   "tc": {
          "type": "long",
              "ignore_above": 256
            }
          }
        },
        "tq": {
          "type": "long",
              "ignore_above": 256
            }
          }
        }

```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 3, 2022, 10:34am UTC](https://discuss.elastic.co/t/how-to-change-field-type-in-elk-from-string-to-numeric-long/303665/9 "2022-05-03T10:34:27Z")

</div>

> [@Next\_generation](#):
>
> ```auto
> "tc": {
> "type": "long",
> "ignore_above": 256
> }
> }
> }
> 
> ```

Just

```auto
"tc": {
  "type": "long"
}

```

---

<div class="post-metadata">

**Author:** ![Next\_generation](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/next_generation/32/105074_2.png) [@Next\_generation](https://discuss.elastic.co/u/Next_generation)\
**Post date:** [May 3, 2022, 11:37am UTC](https://discuss.elastic.co/t/how-to-change-field-type-in-elk-from-string-to-numeric-long/303665/10 "2022-05-03T11:37:01Z")

</div>

Thanks all works!

---

<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:** [May 31, 2022, 11:37am UTC](https://discuss.elastic.co/t/how-to-change-field-type-in-elk-from-string-to-numeric-long/303665/11 "2022-05-31T11:37:13Z")

</div>

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