public static Query newPrefixQuery(String field,InetAddress value,int prefixLength){
  if (value == null) {
    throw new IllegalArgumentException("InetAddress must not be null");
  }
  if (prefixLength < 0 || prefixLength > 8 * value.getAddress().length) {
    throw new IllegalArgumentException("illegal prefixLength '" + prefixLength + "'. Must be 0-32 for IPv4 ranges, 0-128 for IPv6 ranges");
  }
  byte lower[]=value.getAddress();
  byte upper[]=value.getAddress();
  for (int i=prefixLength; i < 8 * lower.length; i++) {
    int m=1 << (7 - (i & 7));
    lower[i >> 3]&=~m;
    upper[i >> 3]|=m;
  }
  try {
    return newRangeQuery(field,InetAddress.getByAddress(lower),InetAddress.getByAddress(upper));
  }
 catch (  UnknownHostException e) {
    throw new AssertionError(e);
  }
}

public static Query newPrefixQuery ( String field , InetAddress value , int prefixLength ) { if ( value == null ) { throw new IllegalArgumentException ( "InetAddress must not be null" ) ; } if ( prefixLength < 0 || prefixLength > 8 * value . getAddress ( ) . length ) { throw new IllegalArgumentException ( "illegal prefixLength '" + prefixLength + "'. Must be 0-32 for IPv4 ranges, 0-128 for IPv6 ranges" ) ; } byte lower [ ] = value . getAddress ( ) ; byte upper [ ] = value . getAddress ( ) ; for ( int i = prefixLength ; i < 8 * lower . length ; i ++ ) { int m = 1 << ( 7 - ( i & 7 ) ) ; lower [ i > > 3 ] &= ~ m ; upper [ i > > 3 ] |= m ; } try { return newRangeQuery ( field , InetAddress . getByAddress ( lower ) , InetAddress . getByAddress ( upper ) ) ; } catch ( UnknownHostException e ) { throw new AssertionError ( e ) ; } }
create a prefix query for matching a cidr network range .
