|
@@ -22,6 +22,7 @@ import org.elasticsearch.action.search.SearchResponse;
|
|
|
import org.elasticsearch.cluster.ClusterState;
|
|
import org.elasticsearch.cluster.ClusterState;
|
|
|
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
|
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
|
|
import org.elasticsearch.common.Strings;
|
|
import org.elasticsearch.common.Strings;
|
|
|
|
|
+import org.elasticsearch.common.geo.builders.PointBuilder;
|
|
|
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
|
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
|
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
@@ -158,6 +159,88 @@ public class GeoShapeIntegrationIT extends ESIntegTestCase {
|
|
|
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
|
|
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ 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", "doc", "0").setSource(source, XContentType.JSON));
|
|
|
|
|
+ indexRandom(true, client().prepareIndex("vector", "doc", "0").setSource(source, XContentType.JSON));
|
|
|
|
|
+
|
|
|
|
|
+ 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));
|
|
|
|
|
+
|
|
|
|
|
+ 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));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private String findNodeName(String index) {
|
|
private String findNodeName(String index) {
|
|
|
ClusterState state = client().admin().cluster().prepareState().get().getState();
|
|
ClusterState state = client().admin().cluster().prepareState().get().getState();
|
|
|
IndexShardRoutingTable shard = state.getRoutingTable().index(index).shard(0);
|
|
IndexShardRoutingTable shard = state.getRoutingTable().index(index).shard(0);
|