|
@@ -9,7 +9,6 @@
|
|
|
package org.elasticsearch.search.geo;
|
|
|
|
|
|
import org.apache.lucene.geo.GeoEncodingUtils;
|
|
|
-import org.elasticsearch.action.search.SearchResponse;
|
|
|
import org.elasticsearch.common.document.DocumentField;
|
|
|
import org.elasticsearch.common.geo.BoundingBox;
|
|
|
import org.elasticsearch.common.geo.GeoPoint;
|
|
@@ -36,7 +35,7 @@ import java.util.Map;
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
|
|
-import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
|
|
+import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailuresAndResponse;
|
|
|
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
import static org.hamcrest.Matchers.is;
|
|
@@ -154,30 +153,30 @@ public class GeoPointScriptDocValuesIT extends ESSingleNodeTestCase {
|
|
|
.get();
|
|
|
|
|
|
client().admin().indices().prepareRefresh("test").get();
|
|
|
-
|
|
|
- SearchResponse searchResponse = client().prepareSearch()
|
|
|
- .addStoredField("_source")
|
|
|
- .addScriptField("lat", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "lat", Collections.emptyMap()))
|
|
|
- .addScriptField("lon", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "lon", Collections.emptyMap()))
|
|
|
- .addScriptField("height", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "height", Collections.emptyMap()))
|
|
|
- .addScriptField("width", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "width", Collections.emptyMap()))
|
|
|
- .addScriptField("label_lat", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "label_lat", Collections.emptyMap()))
|
|
|
- .addScriptField("label_lon", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "label_lon", Collections.emptyMap()))
|
|
|
- .get();
|
|
|
- assertNoFailures(searchResponse);
|
|
|
-
|
|
|
- final double qLat = GeoEncodingUtils.decodeLatitude(GeoEncodingUtils.encodeLatitude(lat));
|
|
|
- final double qLon = GeoEncodingUtils.decodeLongitude(GeoEncodingUtils.encodeLongitude(lon));
|
|
|
-
|
|
|
- Map<String, DocumentField> fields = searchResponse.getHits().getHits()[0].getFields();
|
|
|
- assertThat(fields.get("lat").getValue(), equalTo(qLat));
|
|
|
- assertThat(fields.get("lon").getValue(), equalTo(qLon));
|
|
|
- assertThat(fields.get("height").getValue(), equalTo(0d));
|
|
|
- assertThat(fields.get("width").getValue(), equalTo(0d));
|
|
|
-
|
|
|
- // Check label position is the same point
|
|
|
- assertThat(fields.get("label_lon").getValue(), equalTo(qLon));
|
|
|
- assertThat(fields.get("label_lat").getValue(), equalTo(qLat));
|
|
|
+ assertNoFailuresAndResponse(
|
|
|
+ client().prepareSearch()
|
|
|
+ .addStoredField("_source")
|
|
|
+ .addScriptField("lat", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "lat", Collections.emptyMap()))
|
|
|
+ .addScriptField("lon", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "lon", Collections.emptyMap()))
|
|
|
+ .addScriptField("height", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "height", Collections.emptyMap()))
|
|
|
+ .addScriptField("width", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "width", Collections.emptyMap()))
|
|
|
+ .addScriptField("label_lat", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "label_lat", Collections.emptyMap()))
|
|
|
+ .addScriptField("label_lon", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "label_lon", Collections.emptyMap())),
|
|
|
+ response -> {
|
|
|
+ final double qLat = GeoEncodingUtils.decodeLatitude(GeoEncodingUtils.encodeLatitude(lat));
|
|
|
+ final double qLon = GeoEncodingUtils.decodeLongitude(GeoEncodingUtils.encodeLongitude(lon));
|
|
|
+
|
|
|
+ Map<String, DocumentField> fields = response.getHits().getHits()[0].getFields();
|
|
|
+ assertThat(fields.get("lat").getValue(), equalTo(qLat));
|
|
|
+ assertThat(fields.get("lon").getValue(), equalTo(qLon));
|
|
|
+ assertThat(fields.get("height").getValue(), equalTo(0d));
|
|
|
+ assertThat(fields.get("width").getValue(), equalTo(0d));
|
|
|
+
|
|
|
+ // Check label position is the same point
|
|
|
+ assertThat(fields.get("label_lon").getValue(), equalTo(qLon));
|
|
|
+ assertThat(fields.get("label_lat").getValue(), equalTo(qLat));
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
public void testRandomMultiPoint() throws Exception {
|
|
@@ -199,37 +198,38 @@ public class GeoPointScriptDocValuesIT extends ESSingleNodeTestCase {
|
|
|
|
|
|
client().admin().indices().prepareRefresh("test").get();
|
|
|
|
|
|
- SearchResponse searchResponse = client().prepareSearch()
|
|
|
- .addStoredField("_source")
|
|
|
- .addScriptField("lat", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "lat", Collections.emptyMap()))
|
|
|
- .addScriptField("lon", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "lon", Collections.emptyMap()))
|
|
|
- .addScriptField("height", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "height", Collections.emptyMap()))
|
|
|
- .addScriptField("width", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "width", Collections.emptyMap()))
|
|
|
- .addScriptField("label_lat", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "label_lat", Collections.emptyMap()))
|
|
|
- .addScriptField("label_lon", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "label_lon", Collections.emptyMap()))
|
|
|
- .get();
|
|
|
- assertNoFailures(searchResponse);
|
|
|
-
|
|
|
- for (int i = 0; i < size; i++) {
|
|
|
- lats[i] = GeoEncodingUtils.decodeLatitude(GeoEncodingUtils.encodeLatitude(lats[i]));
|
|
|
- lons[i] = GeoEncodingUtils.decodeLongitude(GeoEncodingUtils.encodeLongitude(lons[i]));
|
|
|
- }
|
|
|
-
|
|
|
- final double centroidLon = Arrays.stream(lons).sum() / size;
|
|
|
- final double centroidLat = Arrays.stream(lats).sum() / size;
|
|
|
- final double width = Arrays.stream(lons).max().getAsDouble() - Arrays.stream(lons).min().getAsDouble();
|
|
|
- final double height = Arrays.stream(lats).max().getAsDouble() - Arrays.stream(lats).min().getAsDouble();
|
|
|
-
|
|
|
- Map<String, DocumentField> fields = searchResponse.getHits().getHits()[0].getFields();
|
|
|
- assertThat(fields.get("lat").getValue(), equalTo(centroidLat));
|
|
|
- assertThat(fields.get("lon").getValue(), equalTo(centroidLon));
|
|
|
- assertThat(fields.get("height").getValue(), equalTo(height));
|
|
|
- assertThat(fields.get("width").getValue(), equalTo(width));
|
|
|
-
|
|
|
- // Check label position is one of the incoming points
|
|
|
- double labelLat = fields.get("label_lat").getValue();
|
|
|
- double labelLon = fields.get("label_lon").getValue();
|
|
|
- assertThat("Label should be one of the points", new GeoPoint(labelLat, labelLon), isMultiPointLabelPosition(lats, lons));
|
|
|
+ assertNoFailuresAndResponse(
|
|
|
+ client().prepareSearch()
|
|
|
+ .addStoredField("_source")
|
|
|
+ .addScriptField("lat", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "lat", Collections.emptyMap()))
|
|
|
+ .addScriptField("lon", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "lon", Collections.emptyMap()))
|
|
|
+ .addScriptField("height", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "height", Collections.emptyMap()))
|
|
|
+ .addScriptField("width", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "width", Collections.emptyMap()))
|
|
|
+ .addScriptField("label_lat", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "label_lat", Collections.emptyMap()))
|
|
|
+ .addScriptField("label_lon", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "label_lon", Collections.emptyMap())),
|
|
|
+ response -> {
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
+ lats[i] = GeoEncodingUtils.decodeLatitude(GeoEncodingUtils.encodeLatitude(lats[i]));
|
|
|
+ lons[i] = GeoEncodingUtils.decodeLongitude(GeoEncodingUtils.encodeLongitude(lons[i]));
|
|
|
+ }
|
|
|
+
|
|
|
+ final double centroidLon = Arrays.stream(lons).sum() / size;
|
|
|
+ final double centroidLat = Arrays.stream(lats).sum() / size;
|
|
|
+ final double width = Arrays.stream(lons).max().getAsDouble() - Arrays.stream(lons).min().getAsDouble();
|
|
|
+ final double height = Arrays.stream(lats).max().getAsDouble() - Arrays.stream(lats).min().getAsDouble();
|
|
|
+
|
|
|
+ Map<String, DocumentField> fields = response.getHits().getHits()[0].getFields();
|
|
|
+ assertThat(fields.get("lat").getValue(), equalTo(centroidLat));
|
|
|
+ assertThat(fields.get("lon").getValue(), equalTo(centroidLon));
|
|
|
+ assertThat(fields.get("height").getValue(), equalTo(height));
|
|
|
+ assertThat(fields.get("width").getValue(), equalTo(width));
|
|
|
+
|
|
|
+ // Check label position is one of the incoming points
|
|
|
+ double labelLat = fields.get("label_lat").getValue();
|
|
|
+ double labelLon = fields.get("label_lon").getValue();
|
|
|
+ assertThat("Label should be one of the points", new GeoPoint(labelLat, labelLon), isMultiPointLabelPosition(lats, lons));
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
public void testNullPoint() throws Exception {
|
|
@@ -240,20 +240,21 @@ public class GeoPointScriptDocValuesIT extends ESSingleNodeTestCase {
|
|
|
|
|
|
client().admin().indices().prepareRefresh("test").get();
|
|
|
|
|
|
- SearchResponse searchResponse = client().prepareSearch()
|
|
|
- .addStoredField("_source")
|
|
|
- .addScriptField("lat", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "lat", Collections.emptyMap()))
|
|
|
- .addScriptField("lon", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "lon", Collections.emptyMap()))
|
|
|
- .addScriptField("height", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "height", Collections.emptyMap()))
|
|
|
- .addScriptField("width", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "width", Collections.emptyMap()))
|
|
|
- .get();
|
|
|
- assertNoFailures(searchResponse);
|
|
|
-
|
|
|
- Map<String, DocumentField> fields = searchResponse.getHits().getHits()[0].getFields();
|
|
|
- assertThat(fields.get("lat").getValue(), equalTo(Double.NaN));
|
|
|
- assertThat(fields.get("lon").getValue(), equalTo(Double.NaN));
|
|
|
- assertThat(fields.get("height").getValue(), equalTo(Double.NaN));
|
|
|
- assertThat(fields.get("width").getValue(), equalTo(Double.NaN));
|
|
|
+ assertNoFailuresAndResponse(
|
|
|
+ client().prepareSearch()
|
|
|
+ .addStoredField("_source")
|
|
|
+ .addScriptField("lat", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "lat", Collections.emptyMap()))
|
|
|
+ .addScriptField("lon", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "lon", Collections.emptyMap()))
|
|
|
+ .addScriptField("height", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "height", Collections.emptyMap()))
|
|
|
+ .addScriptField("width", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "width", Collections.emptyMap())),
|
|
|
+ response -> {
|
|
|
+ Map<String, DocumentField> fields = response.getHits().getHits()[0].getFields();
|
|
|
+ assertThat(fields.get("lat").getValue(), equalTo(Double.NaN));
|
|
|
+ assertThat(fields.get("lon").getValue(), equalTo(Double.NaN));
|
|
|
+ assertThat(fields.get("height").getValue(), equalTo(Double.NaN));
|
|
|
+ assertThat(fields.get("width").getValue(), equalTo(Double.NaN));
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
private static MultiPointLabelPosition isMultiPointLabelPosition(double[] lats, double[] lons) {
|