private void twoParameterBBox(GeoBoundingBoxQueryBuilder filter, Object[] values) { Assert.isTrue(isType(values, GeoPoint.class) || isType(values, String.class), " both elements of boundedBy filter must be type of GeoPoint or text(format lat,lon or geohash)"); if (values[0] instanceof GeoPoint) { GeoPoint topLeft = (GeoPoint) values[0]; GeoPoint bottomRight = (GeoPoint) values[1]; filter.setCorners(topLeft.getLat(), topLeft.getLon(), bottomRight.getLat(), bottomRight.getLon()); } else { String topLeft = (String) values[0]; String bottomRight = (String) values[1]; filter.setCorners(topLeft, bottomRight); } }
/** * A filter to filter based on a bounding box defined by top left and bottom right locations / points * * @param name The location field name. */ public static GeoBoundingBoxQueryBuilder geoBoundingBoxQuery(String name) { return new GeoBoundingBoxQueryBuilder(name); }
/** * Adds corners in OGC standard bbox/ envelop format. * * @param bottomLeft bottom left corner geohash. * @param topRight top right corner geohash. */ public GeoBoundingBoxQueryBuilder setCornersOGC(String bottomLeft, String topRight) { return setCornersOGC(GeoPoint.fromGeohash(bottomLeft), GeoPoint.fromGeohash(topRight)); }
.topLeft(lat, lon) .bottomRight(lat, lon)); filters.add(QueryBuilders.constantScoreQuery(QueryBuilders.termsQuery("place_context", context.name()))); filters.add(QueryBuilders.geoBoundingBoxQuery("location_point") .topLeft(lat_north, lon_west) .bottomRight(lat_south, lon_east)); if (coord.length == 5) filters.add(QueryBuilders.constantScoreQuery(QueryBuilders.termsQuery("location_source", coord[4])));
} else if (token == XContentParser.Token.START_OBJECT) { try { bbox = parseBoundingBox(parser); fieldName = currentFieldName; } catch (Exception e) { final GeoPoint bottomRight = new GeoPoint(bbox[0], bbox[3]); GeoBoundingBoxQueryBuilder builder = new GeoBoundingBoxQueryBuilder(fieldName); builder.setCorners(topLeft, bottomRight); builder.queryName(queryName); builder.boost(boost); builder.type(GeoExecType.fromString(type)); builder.ignoreUnmapped(ignoreUnmapped); if (validationMethod != null) { builder.setValidationMethod(validationMethod);
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(NAME); builder.startObject(fieldName); builder.array(TOP_LEFT_FIELD.getPreferredName(), topLeft.getLon(), topLeft.getLat()); builder.array(BOTTOM_RIGHT_FIELD.getPreferredName(), bottomRight.getLon(), bottomRight.getLat()); builder.endObject(); builder.field(VALIDATION_METHOD_FIELD.getPreferredName(), validationMethod); builder.field(TYPE_FIELD.getPreferredName(), type); builder.field(IGNORE_UNMAPPED_FIELD.getPreferredName(), ignoreUnmapped); printBoostAndQueryName(builder); builder.endObject(); }
QueryValidationException checkLatLon() { if (GeoValidationMethod.isIgnoreMalformed(validationMethod)) { return null; } QueryValidationException validationException = null; // For everything post 2.0 validate latitude and longitude unless validation was explicitly turned off if (GeoUtils.isValidLatitude(topLeft.getLat()) == false) { validationException = addValidationError("top latitude is invalid: " + topLeft.getLat(), validationException); } if (GeoUtils.isValidLongitude(topLeft.getLon()) == false) { validationException = addValidationError("left longitude is invalid: " + topLeft.getLon(), validationException); } if (GeoUtils.isValidLatitude(bottomRight.getLat()) == false) { validationException = addValidationError("bottom latitude is invalid: " + bottomRight.getLat(), validationException); } if (GeoUtils.isValidLongitude(bottomRight.getLon()) == false) { validationException = addValidationError("right longitude is invalid: " + bottomRight.getLon(), validationException); } return validationException; }
QueryValidationException exception = checkLatLon(); if (exception != null) { throw new QueryShardException(context, "couldn't validate latitude/ longitude values", exception);
public GeoBoundingBoxQueryBuilder bottomRight(String geohash) { return bottomRight(GeoPoint.fromGeohash(geohash)); }
} else if (token == XContentParser.Token.START_OBJECT) { try { bbox = parseBoundingBox(parser); fieldName = currentFieldName; } catch (Exception e) { final GeoPoint bottomRight = new GeoPoint(bbox[0], bbox[3]); GeoBoundingBoxQueryBuilder builder = new GeoBoundingBoxQueryBuilder(fieldName); builder.setCorners(topLeft, bottomRight); builder.queryName(queryName); builder.boost(boost); builder.type(GeoExecType.fromString(type)); builder.ignoreUnmapped(ignoreUnmapped); if (validationMethod != null) { builder.setValidationMethod(validationMethod);
.add(QueryBuilders .geoBoundingBoxQuery(propertyName) .topLeft(nwLat, nwLon) .bottomRight(seLat, seLon));
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(NAME); builder.startObject(fieldName); builder.array(TOP_LEFT_FIELD.getPreferredName(), topLeft.getLon(), topLeft.getLat()); builder.array(BOTTOM_RIGHT_FIELD.getPreferredName(), bottomRight.getLon(), bottomRight.getLat()); builder.endObject(); builder.field(VALIDATION_METHOD_FIELD.getPreferredName(), validationMethod); builder.field(TYPE_FIELD.getPreferredName(), type); builder.field(IGNORE_UNMAPPED_FIELD.getPreferredName(), ignoreUnmapped); printBoostAndQueryName(builder); builder.endObject(); }
QueryValidationException checkLatLon() { if (GeoValidationMethod.isIgnoreMalformed(validationMethod)) { return null; } QueryValidationException validationException = null; // For everything post 2.0 validate latitude and longitude unless validation was explicitly turned off if (GeoUtils.isValidLatitude(topLeft.getLat()) == false) { validationException = addValidationError("top latitude is invalid: " + topLeft.getLat(), validationException); } if (GeoUtils.isValidLongitude(topLeft.getLon()) == false) { validationException = addValidationError("left longitude is invalid: " + topLeft.getLon(), validationException); } if (GeoUtils.isValidLatitude(bottomRight.getLat()) == false) { validationException = addValidationError("bottom latitude is invalid: " + bottomRight.getLat(), validationException); } if (GeoUtils.isValidLongitude(bottomRight.getLon()) == false) { validationException = addValidationError("right longitude is invalid: " + bottomRight.getLon(), validationException); } return validationException; }
QueryValidationException exception = checkLatLon(); if (exception != null) { throw new QueryShardException(context, "couldn't validate latitude/ longitude values", exception);
public GeoBoundingBoxQueryBuilder bottomRight(GeoPoint point) { return bottomRight(point.lat(), point.lon()); }
} else if (token == XContentParser.Token.START_OBJECT) { try { bbox = parseBoundingBox(parser); fieldName = currentFieldName; } catch (Exception e) { final GeoPoint bottomRight = new GeoPoint(bbox[0], bbox[3]); GeoBoundingBoxQueryBuilder builder = new GeoBoundingBoxQueryBuilder(fieldName); builder.setCorners(topLeft, bottomRight); builder.queryName(queryName); builder.boost(boost); builder.type(GeoExecType.fromString(type)); builder.ignoreUnmapped(ignoreUnmapped); if (validationMethod != null) { builder.setValidationMethod(validationMethod);
private void oneParameterBBox(GeoBoundingBoxQueryBuilder filter, Object value) { Assert.isTrue(value instanceof GeoBox || value instanceof Box, "single-element of boundedBy filter must be type of GeoBox or Box"); GeoBox geoBBox; if (value instanceof Box) { Box sdbox = (Box) value; geoBBox = GeoBox.fromBox(sdbox); } else { geoBBox = (GeoBox) value; } filter.setCorners(geoBBox.getTopLeft().getLat(), geoBBox.getTopLeft().getLon(), geoBBox.getBottomRight().getLat(), geoBBox.getBottomRight().getLon()); }
/** * A filter to filter based on a bounding box defined by top left and bottom right locations / points * * @param name The location field name. */ public static GeoBoundingBoxQueryBuilder geoBoundingBoxQuery(String name) { return new GeoBoundingBoxQueryBuilder(name); }
/** * Adds corners in OGC standard bbox/ envelop format. * * @param bottomLeft bottom left corner geohash. * @param topRight top right corner geohash. */ public GeoBoundingBoxQueryBuilder setCornersOGC(String bottomLeft, String topRight) { return setCornersOGC(GeoPoint.fromGeohash(bottomLeft), GeoPoint.fromGeohash(topRight)); }
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(NAME); builder.startObject(fieldName); builder.array(TOP_LEFT_FIELD.getPreferredName(), topLeft.getLon(), topLeft.getLat()); builder.array(BOTTOM_RIGHT_FIELD.getPreferredName(), bottomRight.getLon(), bottomRight.getLat()); builder.endObject(); builder.field(VALIDATION_METHOD_FIELD.getPreferredName(), validationMethod); builder.field(TYPE_FIELD.getPreferredName(), type); builder.field(IGNORE_UNMAPPED_FIELD.getPreferredName(), ignoreUnmapped); printBoostAndQueryName(builder); builder.endObject(); }