Skip to content

Commit d1e8cdf

Browse files
committed
Elasticsearch only supports ip addresses as ip, not ranges
1 parent 0b9779a commit d1e8cdf

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

elasticsearch_dsl/field.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class Ip(Field):
310310

311311
def _deserialize(self, data):
312312
# the ipaddress library for pypy, python2.5 and 2.6 only accepts unicode.
313-
return ipaddress.ip_interface(six.u(data))
313+
return ipaddress.ip_address(six.u(data))
314314

315315
def _serialize(self, data):
316316
if data is None:

test_elasticsearch_dsl/test_field.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import base64
2+
import ipaddress
23
from datetime import datetime
34
from dateutil import tz
45

@@ -103,11 +104,10 @@ def test_scaled_float():
103104

104105

105106
def test_ipaddress():
106-
import ipaddress
107107
f = field.Ip()
108-
assert f.deserialize('127.0.0.1/32') == ipaddress.ip_interface(u'127.0.0.1/32')
109-
assert f.deserialize('::1/128') == ipaddress.ip_interface(u'::1/128')
110-
assert f.serialize(f.deserialize('::1/128')) == '::1/128'
108+
assert f.deserialize('127.0.0.1') == ipaddress.ip_address(u'127.0.0.1')
109+
assert f.deserialize('::1') == ipaddress.ip_address(u'::1')
110+
assert f.serialize(f.deserialize('::1')) == '::1'
111111
assert f.deserialize(None) is None
112112
with pytest.raises(ValueError):
113113
assert f.deserialize('not_an_ipaddress')
@@ -134,10 +134,3 @@ def test_binary():
134134
assert f.deserialize(base64.b64encode(b'42')) == b'42'
135135
assert f.deserialize(f.serialize(b'42')) == b'42'
136136
assert f.deserialize(None) is None
137-
138-
139-
140-
141-
142-
143-

0 commit comments

Comments
 (0)