diff options
author | Adrien Grand <jpountz@gmail.com> | 2016-12-08 15:58:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-08 15:58:32 +0100 |
commit | 182e11969952fcc157d306e991214462d1a47ba2 (patch) | |
tree | 7dd12a32f736f4e3a78ee7075df0770efa9d1d6c /core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ip/IpRangeAggregationBuilder.java | |
parent | 30bcb06606e19d91ddc5785d39d8879ab27dc769 (diff) |
IP range masks exclude the maximum address of the range. (#22018)
Closes #22005
Diffstat (limited to 'core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ip/IpRangeAggregationBuilder.java')
-rw-r--r-- | core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ip/IpRangeAggregationBuilder.java | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ip/IpRangeAggregationBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ip/IpRangeAggregationBuilder.java index bd2353b509..cc044ed623 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ip/IpRangeAggregationBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ip/IpRangeAggregationBuilder.java @@ -55,6 +55,7 @@ public final class IpRangeAggregationBuilder private static final InternalAggregation.Type TYPE = new InternalAggregation.Type(NAME); public static class Range implements ToXContent { + private final String key; private final String from; private final String to; @@ -94,8 +95,18 @@ public final class IpRangeAggregationBuilder } this.key = key; try { - this.from = InetAddresses.toAddrString(InetAddress.getByAddress(lower)); - this.to = InetAddresses.toAddrString(InetAddress.getByAddress(upper)); + InetAddress fromAddress = InetAddress.getByAddress(lower); + if (fromAddress.equals(InetAddressPoint.MIN_VALUE)) { + this.from = null; + } else { + this.from = InetAddresses.toAddrString(fromAddress); + } + InetAddress inclusiveToAddress = InetAddress.getByAddress(upper); + if (inclusiveToAddress.equals(InetAddressPoint.MAX_VALUE)) { + this.to = null; + } else { + this.to = InetAddresses.toAddrString(InetAddressPoint.nextUp(inclusiveToAddress)); + } } catch (UnknownHostException bogus) { throw new AssertionError(bogus); } |