# Painless script for converting Long to Hexadecimal

**URL:** https://discuss.elastic.co/t/painless-script-for-converting-long-to-hexadecimal/186563
**Category:** Kibana
**Created:** [June 20, 2019, 1:31am UTC](https://discuss.elastic.co/t/painless-script-for-converting-long-to-hexadecimal/186563 "2019-06-20T01:31:07Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![baerrach](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/baerrach/32/48119_2.png) [@baerrach](https://discuss.elastic.co/u/baerrach)
#### Post date: [June 20, 2019, 1:31am UTC](https://discuss.elastic.co/t/painless-script-for-converting-long-to-hexadecimal/186563/1 "2019-06-20T01:31:08Z")

</div>

[Have Kibana display a numeric field value in hexadecimal](https://discuss.elastic.co/t/have-kibana-display-a-numeric-field-value-in-hexadecimal/106488) is locked, and the example is an image (and broken) which is not useful for cut-and-paste. If it wasn't locked I'd just reply there.

I needed to change the dns.id of packetbeats to hex so that I could easily visualize my wireshark pcap files.

Here is the painless script I used for that.

```
if (doc['dns.id'].size()==0) {
  return "";
}

long dnsId = doc['dns.id'].value;

String asHex = Long.toHexString(dnsId);

return "0x" + asHex
```

---

<div class="post-metadata">

### Author: ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)
#### Post date: [June 27, 2019, 3:08pm UTC](https://discuss.elastic.co/t/painless-script-for-converting-long-to-hexadecimal/186563/2 "2019-06-27T15:08:32Z")

</div>

Hey @baerrach I've just open that topic, could please copy and paste your solution on that topic and close this one?  
Thanks

---

<div class="post-metadata">

### Author: ![baerrach](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/baerrach/32/48119_2.png) [@baerrach](https://discuss.elastic.co/u/baerrach)
#### Post date: [June 27, 2019, 11:18pm UTC](https://discuss.elastic.co/t/painless-script-for-converting-long-to-hexadecimal/186563/3 "2019-06-27T23:18:44Z")

</div>

@markov00 Done. But I can't see how to close this one.

---

<div class="post-metadata">

### Author: ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)
#### Post date: [June 28, 2019, 8:17am UTC](https://discuss.elastic.co/t/painless-script-for-converting-long-to-hexadecimal/186563/4 "2019-06-28T08:17:03Z")

</div>

@baerrach thanks for that ❤  
I will close this for you

---

<div class="post-metadata">

### Author: ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)
#### Post date: [June 28, 2019, 8:17am UTC](https://discuss.elastic.co/t/painless-script-for-converting-long-to-hexadecimal/186563/5 "2019-06-28T08:17:08Z")

</div>


