title: Convert IP (string) into long in elasticsearch/kibana scripted fields
body: <p>I have a field in a doc that is a string representation of ipv4 ("1.2.3.4"), the name of the field is "originating_ip".
  I'm trying to use the scripted fields using the painless language in order to add a new field (originating_ip_calc) to have the int (long) representation of said IPv4.</p>
  
  <p>The following script works in groovy (and from what I understand this should basically work almost the same), but it seems like almost is not in this specific case.</p>
  
  <pre><code>​String[] ipAddressInArray = "1.2.3.4".split("\\.");
  
  long result = 0;
  for (int i = 0; i &lt; ipAddressInArray.length; i++) {
      int power = 3 - i;
      int ip = Integer.parseInt(ipAddressInArray[i]);
      long longIP = (ip * Math.pow(256, power)).toLong();
      result = result + longIP;
  }
  return result;
  </code></pre>
  
  <p>I also looking in <a href="https://stackoverflow.com/questions/36836155/convert-ip-between-ipv4-and-numerical-format-in-java">this question</a> and as you can see from the code above it is based on one of the answers there.</p>
  
  <p>Also tried to work with InetAddress but no luck.</p>