# How to convert string encoding of a keyword field

**URL:** https://discuss.elastic.co/t/how-to-convert-string-encoding-of-a-keyword-field/356463
**Category:** Elasticsearch
**Tags:** painless
**Created:** [March 29, 2024, 12:25pm UTC](https://discuss.elastic.co/t/how-to-convert-string-encoding-of-a-keyword-field/356463 "2024-03-29T12:25:46Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![stefws](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stefws/32/6442_2.png) [@stefws](https://discuss.elastic.co/u/stefws)
#### Post date: [March 29, 2024, 12:25pm UTC](https://discuss.elastic.co/t/how-to-convert-string-encoding-of-a-keyword-field/356463/1 "2024-03-29T12:25:46Z")

</div>

Considering if it may be better to convert hardwired input string encoding to ie. UTF8 for possible better displaying a long the way, eg. like:

```auto
if (ctx.containsKey('epj.role')) {
  String utf8String = new String(ctx.epj.role.getBytes("ISO-8859-1"), "UTF-8");
  ctx.epj.role = utf8String;
}

```

only this code wont compile and thus can't be save and tested, wondering what is wrong with this painless code that ChatGPT hinted me at, any better hints much appreciated, TIA!

---

<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: [April 26, 2024, 12:26pm UTC](https://discuss.elastic.co/t/how-to-convert-string-encoding-of-a-keyword-field/356463/2 "2024-04-26T12:26:22Z")

</div>

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