|
22 | 22 | import org.elasticsearch.cluster.ClusterState;
|
23 | 23 | import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
24 | 24 | import org.elasticsearch.common.Strings;
|
| 25 | +import org.elasticsearch.common.geo.builders.PointBuilder; |
25 | 26 | import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
26 | 27 | import org.elasticsearch.common.xcontent.XContentFactory;
|
27 | 28 | import org.elasticsearch.common.xcontent.XContentType;
|
@@ -158,6 +159,88 @@ public void testIndexShapeRouting() throws Exception {
|
158 | 159 | assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
|
159 | 160 | }
|
160 | 161 |
|
| 162 | + public void testIndexPolygonDateLine() throws Exception { |
| 163 | + String mappingVector = "{\n" + |
| 164 | + " \"properties\": {\n" + |
| 165 | + " \"shape\": {\n" + |
| 166 | + " \"type\": \"geo_shape\"\n" + |
| 167 | + " }\n" + |
| 168 | + " }\n" + |
| 169 | + " }"; |
| 170 | + |
| 171 | + String mappingQuad = "{\n" + |
| 172 | + " \"properties\": {\n" + |
| 173 | + " \"shape\": {\n" + |
| 174 | + " \"type\": \"geo_shape\",\n" + |
| 175 | + " \"tree\": \"quadtree\"\n" + |
| 176 | + " }\n" + |
| 177 | + " }\n" + |
| 178 | + " }"; |
| 179 | + |
| 180 | + |
| 181 | + // create index |
| 182 | + assertAcked(client().admin().indices().prepareCreate("vector").addMapping("doc", mappingVector, XContentType.JSON).get()); |
| 183 | + ensureGreen(); |
| 184 | + |
| 185 | + assertAcked(client().admin().indices().prepareCreate("quad").addMapping("doc", mappingQuad, XContentType.JSON).get()); |
| 186 | + ensureGreen(); |
| 187 | + |
| 188 | + String source = "{\n" + |
| 189 | + " \"shape\" : \"POLYGON((179 0, -179 0, -179 2, 179 2, 179 0))\""+ |
| 190 | + "}"; |
| 191 | + |
| 192 | + indexRandom(true, client().prepareIndex("quad", "doc", "0").setSource(source, XContentType.JSON)); |
| 193 | + indexRandom(true, client().prepareIndex("vector", "doc", "0").setSource(source, XContentType.JSON)); |
| 194 | + |
| 195 | + SearchResponse searchResponse = client().prepareSearch("quad").setQuery( |
| 196 | + geoShapeQuery("shape", new PointBuilder(-179.75, 1)) |
| 197 | + ).get(); |
| 198 | + |
| 199 | + |
| 200 | + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); |
| 201 | + |
| 202 | + searchResponse = client().prepareSearch("quad").setQuery( |
| 203 | + geoShapeQuery("shape", new PointBuilder(90, 1)) |
| 204 | + ).get(); |
| 205 | + |
| 206 | + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); |
| 207 | + |
| 208 | + searchResponse = client().prepareSearch("quad").setQuery( |
| 209 | + geoShapeQuery("shape", new PointBuilder(-180, 1)) |
| 210 | + ).get(); |
| 211 | + |
| 212 | + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); |
| 213 | + searchResponse = client().prepareSearch("quad").setQuery( |
| 214 | + geoShapeQuery("shape", new PointBuilder(180, 1)) |
| 215 | + ).get(); |
| 216 | + |
| 217 | + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); |
| 218 | + |
| 219 | + searchResponse = client().prepareSearch("vector").setQuery( |
| 220 | + geoShapeQuery("shape", new PointBuilder(90, 1)) |
| 221 | + ).get(); |
| 222 | + |
| 223 | + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(0L)); |
| 224 | + |
| 225 | + searchResponse = client().prepareSearch("vector").setQuery( |
| 226 | + geoShapeQuery("shape", new PointBuilder(-179.75, 1)) |
| 227 | + ).get(); |
| 228 | + |
| 229 | + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); |
| 230 | + |
| 231 | + searchResponse = client().prepareSearch("vector").setQuery( |
| 232 | + geoShapeQuery("shape", new PointBuilder(-180, 1)) |
| 233 | + ).get(); |
| 234 | + |
| 235 | + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); |
| 236 | + |
| 237 | + searchResponse = client().prepareSearch("vector").setQuery( |
| 238 | + geoShapeQuery("shape", new PointBuilder(180, 1)) |
| 239 | + ).get(); |
| 240 | + |
| 241 | + assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L)); |
| 242 | + } |
| 243 | + |
161 | 244 | private String findNodeName(String index) {
|
162 | 245 | ClusterState state = client().admin().cluster().prepareState().get().getState();
|
163 | 246 | IndexShardRoutingTable shard = state.getRoutingTable().index(index).shard(0);
|
|
0 commit comments