# Convert a field from string to ip type =\> need decimal?

**URL:** <https://discuss.elastic.co/t/convert-a-field-from-string-to-ip-type-need-decimal/39712>\
**Category:** Elasticsearch\
**Created:** [January 20, 2016, 10:59pm UTC](https://discuss.elastic.co/t/convert-a-field-from-string-to-ip-type-need-decimal/39712 "2016-01-20T22:59:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Thompson](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@Mike\_Thompson](https://discuss.elastic.co/u/Mike_Thompson)\
**Post date:** [January 20, 2016, 10:59pm UTC](https://discuss.elastic.co/t/convert-a-field-from-string-to-ip-type-need-decimal/39712/1 "2016-01-20T22:59:50Z")

</div>

Continuing the discussion from [Convert a field from string to ip type](https://discuss.elastic.co/t/convert-a-field-from-string-to-ip-type/1865):

"version" : {  
"number" : "2.1.1",  
"build\_hash" : "40e2c53a6b6c2972b3d13846e450e66f4375bd71",  
"build\_timestamp" : "2015-12-15T13:05:55Z",  
"build\_snapshot" : false,  
"lucene\_version" : "5.3.1"  
},

I was banging my head on this and I figured out that my template was set correctly however, I keep'd getting errors in logstash.log.

"\_type"=\>"logs", "\_id"=\>"AVJg2HO78OTigFwDifPm", "status"=\>400, "error"=\>{"type"=\>"mapper\_parsing\_exception", "reason"=\>"failed to parse [client\_ip]", "caused\_by"=\>{"type"=\>"number\_format\_exception", "reason"=\>"For input string: "154.250.241.254""}}}}, :level=\>:warn}

this was after enabling the type in the template:

"client\_ip": {  
"type": "ip",  
"store": true  
},

What I got is that an ip string was not wanted but a some other type. I converted it to decimal and it worked. I am not sure of the issue as I looked through (not an experienced java developer ): [https://github.com/elastic/elasticsearch/blob/b6c9eaa24ad314afc83577c4ce3c2eb6798b64bf/core/src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java](https://github.com/elastic/elasticsearch/blob/b6c9eaa24ad314afc83577c4ce3c2eb6798b64bf/core/src/main/java/org/elasticsearch/index/mapper/ip/IpFieldMapper.java)

Since client that is generating the logs is written in python I added this method to solve my problem. Not sure why string would through the error.

def ip2int(addr):  
return struct.unpack("!I", socket.inet\_aton(addr))[0]

Thanks in advance.

---

<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:** [July 5, 2017, 11:22pm UTC](https://discuss.elastic.co/t/convert-a-field-from-string-to-ip-type-need-decimal/39712/2 "2017-07-05T23:22:52Z")

</div>


