How to convert decimal IP to dotted decimal format using a new scripted filed

I have an IP filed in my ES docs which is in decimal format. I want to add a new scripted field which can have the dotted decimal IP value of the decimal IP. So which scripting language will be needed to do so and how to do so.
Any help is greatly appreciated.
Eg : Convert 168,187,530 to


You should be able to do this with Painless Scripting. Here's an example of what conversion from the IP string to decimal would look like in Painless. You are essentially needing to do the opposite.

Unfortunately I don't have any examples of this specific conversion on hand, but since Painless has a similar syntax to Java, you might start by looking at examples of decimal-to-IP conversion in Java, and working back from there (this post has an example that could probably be converted to Painless rather easily).

If you run into any issues, I'd encourage you to check out the Painless language spec, and post back here if you're unable to find answers to your questions.

Hopefully this points you in the right direction!



1 Like

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