mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 18:35:25 +00:00
[TEST] Harden GeoShapeIntegrationTests.
This commit is contained in:
parent
df9346dc67
commit
8a09ec0e06
@ -23,7 +23,6 @@ import org.elasticsearch.action.get.GetResponse;
|
|||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.common.geo.ShapeRelation;
|
import org.elasticsearch.common.geo.ShapeRelation;
|
||||||
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.index.query.FilterBuilders;
|
import org.elasticsearch.index.query.FilterBuilders;
|
||||||
import org.elasticsearch.index.query.GeoShapeFilterBuilder;
|
import org.elasticsearch.index.query.GeoShapeFilterBuilder;
|
||||||
@ -40,7 +39,7 @@ import java.util.Map;
|
|||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
import static org.elasticsearch.index.query.FilterBuilders.geoIntersectionFilter;
|
import static org.elasticsearch.index.query.FilterBuilders.geoIntersectionFilter;
|
||||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
|
|
||||||
public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
||||||
@ -52,10 +51,10 @@ public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
|||||||
.field("type", "geo_shape")
|
.field("type", "geo_shape")
|
||||||
.endObject().endObject()
|
.endObject().endObject()
|
||||||
.endObject().endObject().string();
|
.endObject().endObject().string();
|
||||||
prepareCreate("test").addMapping("type1", mapping).execute().actionGet();
|
assertAcked(prepareCreate("test").addMapping("type1", mapping));
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
client().prepareIndex("test", "type1", "aNullshape").setSource("{\"location\": null}").execute().actionGet();
|
indexRandom(false, client().prepareIndex("test", "type1", "aNullshape").setSource("{\"location\": null}"));
|
||||||
GetResponse result = client().prepareGet("test", "type1", "aNullshape").execute().actionGet();
|
GetResponse result = client().prepareGet("test", "type1", "aNullshape").execute().actionGet();
|
||||||
assertThat(result.getField("location"), nullValue());
|
assertThat(result.getField("location"), nullValue());
|
||||||
}
|
}
|
||||||
@ -68,16 +67,18 @@ public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
|||||||
.field("tree", "quadtree")
|
.field("tree", "quadtree")
|
||||||
.endObject().endObject()
|
.endObject().endObject()
|
||||||
.endObject().endObject().string();
|
.endObject().endObject().string();
|
||||||
prepareCreate("test").addMapping("type1", mapping).execute().actionGet();
|
assertAcked(prepareCreate("test").addMapping("type1", mapping));
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
|
indexRandom(true,
|
||||||
|
|
||||||
client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject()
|
client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject()
|
||||||
.field("name", "Document 1")
|
.field("name", "Document 1")
|
||||||
.startObject("location")
|
.startObject("location")
|
||||||
.field("type", "point")
|
.field("type", "point")
|
||||||
.startArray("coordinates").value(-30).value(-30).endArray()
|
.startArray("coordinates").value(-30).value(-30).endArray()
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject()).execute().actionGet();
|
.endObject()),
|
||||||
|
|
||||||
client().prepareIndex("test", "type1", "2").setSource(jsonBuilder().startObject()
|
client().prepareIndex("test", "type1", "2").setSource(jsonBuilder().startObject()
|
||||||
.field("name", "Document 2")
|
.field("name", "Document 2")
|
||||||
@ -85,10 +86,7 @@ public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
|||||||
.field("type", "point")
|
.field("type", "point")
|
||||||
.startArray("coordinates").value(-45).value(-50).endArray()
|
.startArray("coordinates").value(-45).value(-50).endArray()
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject()).execute().actionGet();
|
.endObject()));
|
||||||
|
|
||||||
refresh();
|
|
||||||
client().admin().indices().prepareRefresh().execute().actionGet();
|
|
||||||
|
|
||||||
ShapeBuilder shape = ShapeBuilder.newEnvelope().topLeft(-45, 45).bottomRight(45, -45);
|
ShapeBuilder shape = ShapeBuilder.newEnvelope().topLeft(-45, 45).bottomRight(45, -45);
|
||||||
|
|
||||||
@ -97,6 +95,7 @@ public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
|||||||
geoIntersectionFilter("location", shape)))
|
geoIntersectionFilter("location", shape)))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertSearchResponse(searchResponse);
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1l));
|
||||||
assertThat(searchResponse.getHits().hits().length, equalTo(1));
|
assertThat(searchResponse.getHits().hits().length, equalTo(1));
|
||||||
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1"));
|
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1"));
|
||||||
@ -105,6 +104,7 @@ public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
|||||||
.setQuery(geoShapeQuery("location", shape))
|
.setQuery(geoShapeQuery("location", shape))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertSearchResponse(searchResponse);
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1l));
|
||||||
assertThat(searchResponse.getHits().hits().length, equalTo(1));
|
assertThat(searchResponse.getHits().hits().length, equalTo(1));
|
||||||
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1"));
|
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1"));
|
||||||
@ -119,10 +119,10 @@ public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
|||||||
.field("tree", "quadtree")
|
.field("tree", "quadtree")
|
||||||
.endObject().endObject()
|
.endObject().endObject()
|
||||||
.endObject().endObject().string();
|
.endObject().endObject().string();
|
||||||
prepareCreate("test").addMapping("type1", mapping).execute().actionGet();
|
assertAcked(prepareCreate("test").addMapping("type1", mapping));
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
client().prepareIndex("test", "type1", "blakely").setSource(jsonBuilder().startObject()
|
indexRandom(true, client().prepareIndex("test", "type1", "blakely").setSource(jsonBuilder().startObject()
|
||||||
.field("name", "Blakely Island")
|
.field("name", "Blakely Island")
|
||||||
.startObject("location")
|
.startObject("location")
|
||||||
.field("type", "polygon")
|
.field("type", "polygon")
|
||||||
@ -133,9 +133,8 @@ public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
|||||||
.startArray().value(-122.83).value(48.57).endArray() // close the polygon
|
.startArray().value(-122.83).value(48.57).endArray() // close the polygon
|
||||||
.endArray().endArray()
|
.endArray().endArray()
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject()).execute().actionGet();
|
.endObject()));
|
||||||
|
|
||||||
client().admin().indices().prepareRefresh().execute().actionGet();
|
|
||||||
|
|
||||||
ShapeBuilder query = ShapeBuilder.newEnvelope().topLeft(-122.88, 48.62).bottomRight(-122.82, 48.54);
|
ShapeBuilder query = ShapeBuilder.newEnvelope().topLeft(-122.88, 48.62).bottomRight(-122.82, 48.54);
|
||||||
|
|
||||||
@ -146,6 +145,7 @@ public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
|||||||
geoIntersectionFilter("location", query)))
|
geoIntersectionFilter("location", query)))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertSearchResponse(searchResponse);
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1l));
|
||||||
assertThat(searchResponse.getHits().hits().length, equalTo(1));
|
assertThat(searchResponse.getHits().hits().length, equalTo(1));
|
||||||
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("blakely"));
|
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("blakely"));
|
||||||
@ -159,41 +159,38 @@ public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
|||||||
.field("tree", "quadtree")
|
.field("tree", "quadtree")
|
||||||
.endObject().endObject()
|
.endObject().endObject()
|
||||||
.endObject().endObject().string();
|
.endObject().endObject().string();
|
||||||
prepareCreate("test").addMapping("type1", mapping).execute().actionGet();
|
assertAcked(prepareCreate("test").addMapping("type1", mapping));
|
||||||
|
createIndex("shapes");
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
|
ShapeBuilder shape = ShapeBuilder.newEnvelope().topLeft(-45, 45).bottomRight(45, -45);
|
||||||
|
|
||||||
|
indexRandom(true,
|
||||||
|
client().prepareIndex("shapes", "shape_type", "Big_Rectangle").setSource(jsonBuilder().startObject()
|
||||||
|
.field("shape", shape).endObject()),
|
||||||
client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject()
|
client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject()
|
||||||
.field("name", "Document 1")
|
.field("name", "Document 1")
|
||||||
.startObject("location")
|
.startObject("location")
|
||||||
.field("type", "point")
|
.field("type", "point")
|
||||||
.startArray("coordinates").value(-30).value(-30).endArray()
|
.startArray("coordinates").value(-30).value(-30).endArray()
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject()).execute().actionGet();
|
.endObject()));
|
||||||
|
|
||||||
refresh();
|
|
||||||
|
|
||||||
ShapeBuilder shape = ShapeBuilder.newEnvelope().topLeft(-45, 45).bottomRight(45, -45);
|
|
||||||
XContentBuilder shapeContent = jsonBuilder().startObject()
|
|
||||||
.field("shape", shape);
|
|
||||||
shapeContent.endObject();
|
|
||||||
createIndex("shapes");
|
|
||||||
ensureGreen();
|
|
||||||
client().prepareIndex("shapes", "shape_type", "Big_Rectangle").setSource(shapeContent).execute().actionGet();
|
|
||||||
refresh();
|
|
||||||
|
|
||||||
SearchResponse searchResponse = client().prepareSearch("test")
|
SearchResponse searchResponse = client().prepareSearch("test")
|
||||||
.setQuery(filteredQuery(matchAllQuery(),
|
.setQuery(filteredQuery(matchAllQuery(),
|
||||||
geoIntersectionFilter("location", "Big_Rectangle", "shape_type")))
|
geoIntersectionFilter("location", "Big_Rectangle", "shape_type")))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertSearchResponse(searchResponse);
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1l));
|
||||||
assertThat(searchResponse.getHits().hits().length, equalTo(1));
|
assertThat(searchResponse.getHits().hits().length, equalTo(1));
|
||||||
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1"));
|
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1"));
|
||||||
|
|
||||||
searchResponse = client().prepareSearch()
|
searchResponse = client().prepareSearch("test")
|
||||||
.setQuery(geoShapeQuery("location", "Big_Rectangle", "shape_type"))
|
.setQuery(geoShapeQuery("location", "Big_Rectangle", "shape_type"))
|
||||||
.execute().actionGet();
|
.execute().actionGet();
|
||||||
|
|
||||||
|
assertSearchResponse(searchResponse);
|
||||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1l));
|
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1l));
|
||||||
assertThat(searchResponse.getHits().hits().length, equalTo(1));
|
assertThat(searchResponse.getHits().hits().length, equalTo(1));
|
||||||
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1"));
|
assertThat(searchResponse.getHits().getAt(0).id(), equalTo("1"));
|
||||||
@ -220,7 +217,7 @@ public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParsingMultipleShapes() throws IOException {
|
public void testParsingMultipleShapes() throws Exception {
|
||||||
String mapping = XContentFactory.jsonBuilder()
|
String mapping = XContentFactory.jsonBuilder()
|
||||||
.startObject()
|
.startObject()
|
||||||
.startObject("type1")
|
.startObject("type1")
|
||||||
@ -236,15 +233,14 @@ public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
|||||||
.endObject()
|
.endObject()
|
||||||
.string();
|
.string();
|
||||||
|
|
||||||
prepareCreate("test").addMapping("type1", mapping).execute().actionGet();
|
assertAcked(prepareCreate("test").addMapping("type1", mapping));
|
||||||
ensureYellow();
|
ensureYellow();
|
||||||
|
|
||||||
String p1 = "\"location1\" : {\"type\":\"polygon\", \"coordinates\":[[[-10,-10],[10,-10],[10,10],[-10,10],[-10,-10]]]}";
|
String p1 = "\"location1\" : {\"type\":\"polygon\", \"coordinates\":[[[-10,-10],[10,-10],[10,10],[-10,10],[-10,-10]]]}";
|
||||||
String p2 = "\"location2\" : {\"type\":\"polygon\", \"coordinates\":[[[-20,-20],[20,-20],[20,20],[-20,20],[-20,-20]]]}";
|
String p2 = "\"location2\" : {\"type\":\"polygon\", \"coordinates\":[[[-20,-20],[20,-20],[20,20],[-20,20],[-20,-20]]]}";
|
||||||
String o1 = "{" + p1 + ", " + p2 + "}";
|
String o1 = "{" + p1 + ", " + p2 + "}";
|
||||||
|
|
||||||
client().prepareIndex("test", "type1", "1").setSource(o1).execute().actionGet();
|
indexRandom(true, client().prepareIndex("test", "type1", "1").setSource(o1));
|
||||||
client().admin().indices().prepareRefresh("test").execute().actionGet();
|
|
||||||
|
|
||||||
String filter = "{\"geo_shape\": {\"location2\": {\"indexed_shape\": {"
|
String filter = "{\"geo_shape\": {\"location2\": {\"indexed_shape\": {"
|
||||||
+ "\"id\": \"1\","
|
+ "\"id\": \"1\","
|
||||||
@ -254,20 +250,23 @@ public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
|||||||
+ "}}}}";
|
+ "}}}}";
|
||||||
|
|
||||||
SearchResponse result = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery()).setPostFilter(filter).execute().actionGet();
|
SearchResponse result = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery()).setPostFilter(filter).execute().actionGet();
|
||||||
|
assertSearchResponse(result);
|
||||||
assertHitCount(result, 1);
|
assertHitCount(result, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testShapeFetching_path() throws IOException {
|
public void testShapeFetching_path() throws Exception {
|
||||||
prepareCreate("shapes").execute().actionGet();
|
createIndex("shapes");
|
||||||
prepareCreate("test").addMapping("type", "location", "type=geo_shape").execute().actionGet();
|
assertAcked(prepareCreate("test").addMapping("type", "location", "type=geo_shape"));
|
||||||
|
|
||||||
String location = "\"location\" : {\"type\":\"polygon\", \"coordinates\":[[[-10,-10],[10,-10],[10,10],[-10,10],[-10,-10]]]}";
|
String location = "\"location\" : {\"type\":\"polygon\", \"coordinates\":[[[-10,-10],[10,-10],[10,10],[-10,10],[-10,-10]]]}";
|
||||||
|
indexRandom(true,
|
||||||
client().prepareIndex("shapes", "type", "1")
|
client().prepareIndex("shapes", "type", "1")
|
||||||
.setSource(
|
.setSource(
|
||||||
String.format(
|
String.format(
|
||||||
Locale.ROOT, "{ %s, \"1\" : { %s, \"2\" : { %s, \"3\" : { %s } }} }", location, location, location, location
|
Locale.ROOT, "{ %s, \"1\" : { %s, \"2\" : { %s, \"3\" : { %s } }} }", location, location, location, location
|
||||||
)
|
)
|
||||||
).get();
|
),
|
||||||
client().prepareIndex("test", "type", "1")
|
client().prepareIndex("test", "type", "1")
|
||||||
.setSource(jsonBuilder().startObject().startObject("location")
|
.setSource(jsonBuilder().startObject().startObject("location")
|
||||||
.field("type", "polygon")
|
.field("type", "polygon")
|
||||||
@ -278,32 +277,36 @@ public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
|||||||
.startArray().value(-20).value(20).endArray()
|
.startArray().value(-20).value(20).endArray()
|
||||||
.startArray().value(-20).value(-20).endArray()
|
.startArray().value(-20).value(-20).endArray()
|
||||||
.endArray().endArray()
|
.endArray().endArray()
|
||||||
.endObject().endObject()).get();
|
.endObject().endObject()));
|
||||||
client().admin().indices().prepareRefresh("test", "shapes").execute().actionGet();
|
ensureSearchable("test", "shapes");
|
||||||
|
|
||||||
GeoShapeFilterBuilder filter = FilterBuilders.geoShapeFilter("location", "1", "type", ShapeRelation.INTERSECTS)
|
GeoShapeFilterBuilder filter = FilterBuilders.geoShapeFilter("location", "1", "type", ShapeRelation.INTERSECTS)
|
||||||
.indexedShapeIndex("shapes")
|
.indexedShapeIndex("shapes")
|
||||||
.indexedShapePath("location");
|
.indexedShapePath("location");
|
||||||
SearchResponse result = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery())
|
SearchResponse result = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery())
|
||||||
.setPostFilter(filter).get();
|
.setPostFilter(filter).get();
|
||||||
|
assertSearchResponse(result);
|
||||||
assertHitCount(result, 1);
|
assertHitCount(result, 1);
|
||||||
filter = FilterBuilders.geoShapeFilter("location", "1", "type", ShapeRelation.INTERSECTS)
|
filter = FilterBuilders.geoShapeFilter("location", "1", "type", ShapeRelation.INTERSECTS)
|
||||||
.indexedShapeIndex("shapes")
|
.indexedShapeIndex("shapes")
|
||||||
.indexedShapePath("1.location");
|
.indexedShapePath("1.location");
|
||||||
result = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery())
|
result = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery())
|
||||||
.setPostFilter(filter).get();
|
.setPostFilter(filter).get();
|
||||||
|
assertSearchResponse(result);
|
||||||
assertHitCount(result, 1);
|
assertHitCount(result, 1);
|
||||||
filter = FilterBuilders.geoShapeFilter("location", "1", "type", ShapeRelation.INTERSECTS)
|
filter = FilterBuilders.geoShapeFilter("location", "1", "type", ShapeRelation.INTERSECTS)
|
||||||
.indexedShapeIndex("shapes")
|
.indexedShapeIndex("shapes")
|
||||||
.indexedShapePath("1.2.location");
|
.indexedShapePath("1.2.location");
|
||||||
result = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery())
|
result = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery())
|
||||||
.setPostFilter(filter).get();
|
.setPostFilter(filter).get();
|
||||||
|
assertSearchResponse(result);
|
||||||
assertHitCount(result, 1);
|
assertHitCount(result, 1);
|
||||||
filter = FilterBuilders.geoShapeFilter("location", "1", "type", ShapeRelation.INTERSECTS)
|
filter = FilterBuilders.geoShapeFilter("location", "1", "type", ShapeRelation.INTERSECTS)
|
||||||
.indexedShapeIndex("shapes")
|
.indexedShapeIndex("shapes")
|
||||||
.indexedShapePath("1.2.3.location");
|
.indexedShapePath("1.2.3.location");
|
||||||
result = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery())
|
result = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery())
|
||||||
.setPostFilter(filter).get();
|
.setPostFilter(filter).get();
|
||||||
|
assertSearchResponse(result);
|
||||||
assertHitCount(result, 1);
|
assertHitCount(result, 1);
|
||||||
|
|
||||||
// now test the query variant
|
// now test the query variant
|
||||||
@ -311,21 +314,25 @@ public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
|||||||
.indexedShapeIndex("shapes")
|
.indexedShapeIndex("shapes")
|
||||||
.indexedShapePath("location");
|
.indexedShapePath("location");
|
||||||
result = client().prepareSearch("test").setQuery(query).get();
|
result = client().prepareSearch("test").setQuery(query).get();
|
||||||
|
assertSearchResponse(result);
|
||||||
assertHitCount(result, 1);
|
assertHitCount(result, 1);
|
||||||
query = QueryBuilders.geoShapeQuery("location", "1", "type")
|
query = QueryBuilders.geoShapeQuery("location", "1", "type")
|
||||||
.indexedShapeIndex("shapes")
|
.indexedShapeIndex("shapes")
|
||||||
.indexedShapePath("1.location");
|
.indexedShapePath("1.location");
|
||||||
result = client().prepareSearch("test").setQuery(query).get();
|
result = client().prepareSearch("test").setQuery(query).get();
|
||||||
|
assertSearchResponse(result);
|
||||||
assertHitCount(result, 1);
|
assertHitCount(result, 1);
|
||||||
query = QueryBuilders.geoShapeQuery("location", "1", "type")
|
query = QueryBuilders.geoShapeQuery("location", "1", "type")
|
||||||
.indexedShapeIndex("shapes")
|
.indexedShapeIndex("shapes")
|
||||||
.indexedShapePath("1.2.location");
|
.indexedShapePath("1.2.location");
|
||||||
result = client().prepareSearch("test").setQuery(query).get();
|
result = client().prepareSearch("test").setQuery(query).get();
|
||||||
|
assertSearchResponse(result);
|
||||||
assertHitCount(result, 1);
|
assertHitCount(result, 1);
|
||||||
query = QueryBuilders.geoShapeQuery("location", "1", "type")
|
query = QueryBuilders.geoShapeQuery("location", "1", "type")
|
||||||
.indexedShapeIndex("shapes")
|
.indexedShapeIndex("shapes")
|
||||||
.indexedShapePath("1.2.3.location");
|
.indexedShapePath("1.2.3.location");
|
||||||
result = client().prepareSearch("test").setQuery(query).get();
|
result = client().prepareSearch("test").setQuery(query).get();
|
||||||
|
assertSearchResponse(result);
|
||||||
assertHitCount(result, 1);
|
assertHitCount(result, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,17 +347,17 @@ public class GeoShapeIntegrationTests extends ElasticsearchIntegrationTest {
|
|||||||
.endObject()
|
.endObject()
|
||||||
.endObject().endObject()
|
.endObject().endObject()
|
||||||
.string();
|
.string();
|
||||||
prepareCreate("test").addMapping("type1", mapping).execute().actionGet();
|
assertAcked(prepareCreate("test").addMapping("type1", mapping));
|
||||||
ensureGreen();
|
ensureGreen();
|
||||||
|
|
||||||
|
indexRandom(true,
|
||||||
client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject()
|
client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject()
|
||||||
.field("name", "Document 1")
|
.field("name", "Document 1")
|
||||||
.startObject("location")
|
.startObject("location")
|
||||||
.field("type", "envelope")
|
.field("type", "envelope")
|
||||||
.startArray("coordinates").startArray().value(-45.0).value(45).endArray().startArray().value(45).value(-45).endArray().endArray()
|
.startArray("coordinates").startArray().value(-45.0).value(45).endArray().startArray().value(45).value(-45).endArray().endArray()
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject()).execute().actionGet();
|
.endObject()));
|
||||||
|
|
||||||
client().admin().indices().prepareRefresh("test").execute().actionGet();
|
|
||||||
|
|
||||||
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
|
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
|
||||||
assertThat(searchResponse.getHits().totalHits(), equalTo(1L));
|
assertThat(searchResponse.getHits().totalHits(), equalTo(1L));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user