From 182e11969952fcc157d306e991214462d1a47ba2 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 8 Dec 2016 15:58:32 +0100 Subject: IP range masks exclude the maximum address of the range. (#22018) Closes #22005 --- .../bucket/range/ip/IpRangeAggregationBuilder.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ip/IpRangeAggregationBuilder.java') 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); } -- cgit v1.2.3