use of org.opensearch.common.geo.builders.PointBuilder in project OpenSearch by opensearch-project.
the class GeoShapeIntegrationIT method testIndexPolygonDateLine.
public void testIndexPolygonDateLine() throws Exception {
String mappingVector = "{\n" + " \"properties\": {\n" + " \"shape\": {\n" + " \"type\": \"geo_shape\"\n" + " }\n" + " }\n" + " }";
String mappingQuad = "{\n" + " \"properties\": {\n" + " \"shape\": {\n" + " \"type\": \"geo_shape\",\n" + " \"tree\": \"quadtree\"\n" + " }\n" + " }\n" + " }";
// create index
assertAcked(client().admin().indices().prepareCreate("vector").addMapping("doc", mappingVector, XContentType.JSON).get());
ensureGreen();
assertAcked(client().admin().indices().prepareCreate("quad").addMapping("doc", mappingQuad, XContentType.JSON).get());
ensureGreen();
String source = "{\n" + " \"shape\" : \"POLYGON((179 0, -179 0, -179 2, 179 2, 179 0))\"" + "}";
indexRandom(true, client().prepareIndex("quad").setId("0").setSource(source, XContentType.JSON));
indexRandom(true, client().prepareIndex("vector").setId("0").setSource(source, XContentType.JSON));
try {
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
updateSettingsRequest.persistentSettings(Settings.builder().put("search.allow_expensive_queries", true));
assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
SearchResponse searchResponse = client().prepareSearch("quad").setQuery(geoShapeQuery("shape", new PointBuilder(-179.75, 1))).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
searchResponse = client().prepareSearch("quad").setQuery(geoShapeQuery("shape", new PointBuilder(90, 1))).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L));
searchResponse = client().prepareSearch("quad").setQuery(geoShapeQuery("shape", new PointBuilder(-180, 1))).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
searchResponse = client().prepareSearch("quad").setQuery(geoShapeQuery("shape", new PointBuilder(180, 1))).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
} finally {
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
updateSettingsRequest.persistentSettings(Settings.builder().put("search.allow_expensive_queries", (String) null));
assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
}
SearchResponse searchResponse = client().prepareSearch("vector").setQuery(geoShapeQuery("shape", new PointBuilder(90, 1))).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L));
searchResponse = client().prepareSearch("vector").setQuery(geoShapeQuery("shape", new PointBuilder(-179.75, 1))).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
searchResponse = client().prepareSearch("vector").setQuery(geoShapeQuery("shape", new PointBuilder(-180, 1))).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
searchResponse = client().prepareSearch("vector").setQuery(geoShapeQuery("shape", new PointBuilder(180, 1))).get();
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
}
use of org.opensearch.common.geo.builders.PointBuilder in project OpenSearch by opensearch-project.
the class ExternalMapper method parse.
@Override
public void parse(ParseContext context) throws IOException {
byte[] bytes = "Hello world".getBytes(Charset.defaultCharset());
binMapper.parse(context.createExternalValueContext(bytes));
boolMapper.parse(context.createExternalValueContext(true));
// Let's add a Dummy Point
double lat = 42.0;
double lng = 51.0;
ArrayList<GeoPoint> points = new ArrayList<>();
points.add(new GeoPoint(lat, lng));
pointMapper.parse(context.createExternalValueContext(points));
// Let's add a Dummy Shape
if (shapeMapper instanceof GeoShapeFieldMapper) {
shapeMapper.parse(context.createExternalValueContext(new Point(-100, 45)));
} else {
PointBuilder pb = new PointBuilder(-100, 45);
shapeMapper.parse(context.createExternalValueContext(pb.buildS4J()));
}
context = context.createExternalValueContext(generatedValue);
// Let's add a Original String
stringMapper.parse(context);
multiFields.parse(this, context);
}
use of org.opensearch.common.geo.builders.PointBuilder in project OpenSearch by opensearch-project.
the class ShapeBuilderTests method testNewPoint.
public void testNewPoint() {
PointBuilder pb = new PointBuilder().coordinate(-100, 45);
Point point = pb.buildS4J();
assertEquals(-100D, point.getX(), 0.0d);
assertEquals(45D, point.getY(), 0.0d);
org.opensearch.geometry.Point geoPoint = pb.buildGeometry();
assertEquals(-100D, geoPoint.getX(), 0.0d);
assertEquals(45D, geoPoint.getY(), 0.0d);
}
use of org.opensearch.common.geo.builders.PointBuilder in project OpenSearch by opensearch-project.
the class GeoWKTShapeParserTests method testUnexpectedShapeException.
public void testUnexpectedShapeException() throws IOException {
XContentBuilder builder = toWKTContent(new PointBuilder(-1, 2), false);
XContentParser parser = createParser(builder);
parser.nextToken();
OpenSearchParseException e = expectThrows(OpenSearchParseException.class, () -> GeoWKTParser.parseExpectedType(parser, GeoShapeType.POLYGON));
assertThat(e, hasToString(containsString("Expected geometry type [polygon] but found [point]")));
}
use of org.opensearch.common.geo.builders.PointBuilder in project OpenSearch by opensearch-project.
the class GeoWKTShapeParserTests method testParsePoint.
@Override
public void testParsePoint() throws IOException, ParseException {
GeoPoint p = RandomShapeGenerator.randomPoint(random());
Coordinate c = new Coordinate(p.lon(), p.lat());
Point expected = GEOMETRY_FACTORY.createPoint(c);
assertExpected(new JtsPoint(expected, SPATIAL_CONTEXT), new PointBuilder().coordinate(c), true);
assertExpected(new org.opensearch.geometry.Point(p.lon(), p.lat()), new PointBuilder().coordinate(c), false);
assertMalformed(new PointBuilder().coordinate(c));
}
Aggregations