diff --git a/server/src/main/java/org/opensearch/index/mapper/IpFieldMapper.java b/server/src/main/java/org/opensearch/index/mapper/IpFieldMapper.java index baa391191613c..a6118736d615a 100644 --- a/server/src/main/java/org/opensearch/index/mapper/IpFieldMapper.java +++ b/server/src/main/java/org/opensearch/index/mapper/IpFieldMapper.java @@ -227,24 +227,20 @@ protected Object parseSourceValue(Object value) { public Query termQuery(Object value, @Nullable QueryShardContext context) { failIfNotIndexedAndNoDocValues(); final PointRangeQuery pointQuery; - { - final Query query; - if (value instanceof InetAddress) { - query = InetAddressPoint.newExactQuery(name(), (InetAddress) value); + if (value instanceof InetAddress) { + pointQuery = (PointRangeQuery) InetAddressPoint.newExactQuery(name(), (InetAddress) value); + } else { + if (value instanceof BytesRef) { + value = ((BytesRef) value).utf8ToString(); + } + String term = value.toString(); + if (term.contains("/")) { + final Tuple cidr = InetAddresses.parseCidr(term); + pointQuery = (PointRangeQuery) InetAddressPoint.newPrefixQuery(name(), cidr.v1(), cidr.v2()); } else { - if (value instanceof BytesRef) { - value = ((BytesRef) value).utf8ToString(); - } - String term = value.toString(); - if (term.contains("/")) { - final Tuple cidr = InetAddresses.parseCidr(term); - query = InetAddressPoint.newPrefixQuery(name(), cidr.v1(), cidr.v2()); - } else { - InetAddress address = InetAddresses.forString(term); - query = InetAddressPoint.newExactQuery(name(), address); - } + InetAddress address = InetAddresses.forString(term); + pointQuery = (PointRangeQuery) InetAddressPoint.newExactQuery(name(), address); } - pointQuery = (PointRangeQuery) query; } Query dvQuery = null; if (hasDocValues()) {