Geo: All geo components that accept an array of [lat, lon] to change to do [lon, lat] to conform with GeoJSON, closes #661.
This commit is contained in:
parent
f8b5628db9
commit
5da14a7ed1
|
@ -227,12 +227,12 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
||||||
if (token == XContentParser.Token.START_ARRAY) {
|
if (token == XContentParser.Token.START_ARRAY) {
|
||||||
token = context.parser().nextToken();
|
token = context.parser().nextToken();
|
||||||
if (token == XContentParser.Token.START_ARRAY) {
|
if (token == XContentParser.Token.START_ARRAY) {
|
||||||
// its an array of array of lat/lon [ [1.2, 1.3], [1.4, 1.5] ]
|
// its an array of array of lon/lat [ [1.2, 1.3], [1.4, 1.5] ]
|
||||||
while (token != XContentParser.Token.END_ARRAY) {
|
while (token != XContentParser.Token.END_ARRAY) {
|
||||||
token = context.parser().nextToken();
|
|
||||||
Double lat = context.parser().doubleValue();
|
|
||||||
token = context.parser().nextToken();
|
token = context.parser().nextToken();
|
||||||
Double lon = context.parser().doubleValue();
|
Double lon = context.parser().doubleValue();
|
||||||
|
token = context.parser().nextToken();
|
||||||
|
Double lat = context.parser().doubleValue();
|
||||||
while ((token = context.parser().nextToken()) != XContentParser.Token.END_ARRAY) {
|
while ((token = context.parser().nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -242,9 +242,9 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
||||||
} else {
|
} else {
|
||||||
// its an array of other possible values
|
// its an array of other possible values
|
||||||
if (token == XContentParser.Token.VALUE_NUMBER) {
|
if (token == XContentParser.Token.VALUE_NUMBER) {
|
||||||
Double lat = context.parser().doubleValue();
|
|
||||||
token = context.parser().nextToken();
|
|
||||||
Double lon = context.parser().doubleValue();
|
Double lon = context.parser().doubleValue();
|
||||||
|
token = context.parser().nextToken();
|
||||||
|
Double lat = context.parser().doubleValue();
|
||||||
while ((token = context.parser().nextToken()) != XContentParser.Token.END_ARRAY) {
|
while ((token = context.parser().nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,12 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds top left point.
|
||||||
|
*
|
||||||
|
* @param lat The latitude
|
||||||
|
* @param lon The longitude
|
||||||
|
*/
|
||||||
public GeoBoundingBoxFilterBuilder topLeft(double lat, double lon) {
|
public GeoBoundingBoxFilterBuilder topLeft(double lat, double lon) {
|
||||||
topLeft = new GeoBoundingBoxFilter.Point();
|
topLeft = new GeoBoundingBoxFilter.Point();
|
||||||
topLeft.lat = lat;
|
topLeft.lat = lat;
|
||||||
|
@ -55,6 +61,12 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds bottom right point.
|
||||||
|
*
|
||||||
|
* @param lat The latitude
|
||||||
|
* @param lon The longitude
|
||||||
|
*/
|
||||||
public GeoBoundingBoxFilterBuilder bottomRight(double lat, double lon) {
|
public GeoBoundingBoxFilterBuilder bottomRight(double lat, double lon) {
|
||||||
bottomRight = new GeoBoundingBoxFilter.Point();
|
bottomRight = new GeoBoundingBoxFilter.Point();
|
||||||
bottomRight.lat = lat;
|
bottomRight.lat = lat;
|
||||||
|
@ -95,7 +107,7 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
|
||||||
if (topLeftGeohash != null) {
|
if (topLeftGeohash != null) {
|
||||||
builder.field("top_left", topLeftGeohash);
|
builder.field("top_left", topLeftGeohash);
|
||||||
} else if (topLeft != null) {
|
} else if (topLeft != null) {
|
||||||
builder.startArray("top_left").value(topLeft.lat).value(topLeft.lon).endArray();
|
builder.startArray("top_left").value(topLeft.lon).value(topLeft.lat).endArray();
|
||||||
} else {
|
} else {
|
||||||
throw new QueryBuilderException("geo_bounding_box requires 'top_left' to be set");
|
throw new QueryBuilderException("geo_bounding_box requires 'top_left' to be set");
|
||||||
}
|
}
|
||||||
|
@ -103,7 +115,7 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
|
||||||
if (bottomRightGeohash != null) {
|
if (bottomRightGeohash != null) {
|
||||||
builder.field("bottom_right", bottomRightGeohash);
|
builder.field("bottom_right", bottomRightGeohash);
|
||||||
} else if (bottomRight != null) {
|
} else if (bottomRight != null) {
|
||||||
builder.startArray("bottom_right").value(bottomRight.lat).value(bottomRight.lon).endArray();
|
builder.startArray("bottom_right").value(bottomRight.lon).value(bottomRight.lat).endArray();
|
||||||
} else {
|
} else {
|
||||||
throw new QueryBuilderException("geo_bounding_box requires 'bottom_right' to be set");
|
throw new QueryBuilderException("geo_bounding_box requires 'bottom_right' to be set");
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,10 +82,10 @@ public class GeoBoundingBoxFilterParser extends AbstractIndexComponent implement
|
||||||
}
|
}
|
||||||
|
|
||||||
if (point != null) {
|
if (point != null) {
|
||||||
token = parser.nextToken();
|
|
||||||
point.lat = parser.doubleValue();
|
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
point.lon = parser.doubleValue();
|
point.lon = parser.doubleValue();
|
||||||
|
token = parser.nextToken();
|
||||||
|
point.lat = parser.doubleValue();
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class GeoDistanceFilterBuilder extends BaseFilterBuilder {
|
||||||
if (geohash != null) {
|
if (geohash != null) {
|
||||||
builder.field(name, geohash);
|
builder.field(name, geohash);
|
||||||
} else {
|
} else {
|
||||||
builder.startArray(name).value(lat).value(lon).endArray();
|
builder.startArray(name).value(lon).value(lat).endArray();
|
||||||
}
|
}
|
||||||
builder.field("distance", distance);
|
builder.field("distance", distance);
|
||||||
if (geoDistance != null) {
|
if (geoDistance != null) {
|
||||||
|
|
|
@ -81,10 +81,10 @@ public class GeoDistanceFilterParser extends AbstractIndexComponent implements X
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||||
token = parser.nextToken();
|
|
||||||
lat = parser.doubleValue();
|
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
lon = parser.doubleValue();
|
lon = parser.doubleValue();
|
||||||
|
token = parser.nextToken();
|
||||||
|
lat = parser.doubleValue();
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -152,9 +152,9 @@ public class GeoDistanceFilterParser extends AbstractIndexComponent implements X
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vDistance instanceof Number) {
|
if (vDistance instanceof Number) {
|
||||||
distance = unit.toMiles(((Number)vDistance).doubleValue());
|
distance = unit.toMiles(((Number) vDistance).doubleValue());
|
||||||
} else {
|
} else {
|
||||||
distance = DistanceUnit.parse((String)vDistance, unit, DistanceUnit.MILES);
|
distance = DistanceUnit.parse((String) vDistance, unit, DistanceUnit.MILES);
|
||||||
}
|
}
|
||||||
|
|
||||||
MapperService mapperService = parseContext.mapperService();
|
MapperService mapperService = parseContext.mapperService();
|
||||||
|
|
|
@ -44,6 +44,13 @@ public class GeoPolygonFilterBuilder extends BaseFilterBuilder {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a point with lat and lon
|
||||||
|
*
|
||||||
|
* @param lat The latitude
|
||||||
|
* @param lon The longitude
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public GeoPolygonFilterBuilder addPoint(double lat, double lon) {
|
public GeoPolygonFilterBuilder addPoint(double lat, double lon) {
|
||||||
points.add(new GeoPolygonFilter.Point(lat, lon));
|
points.add(new GeoPolygonFilter.Point(lat, lon));
|
||||||
return this;
|
return this;
|
||||||
|
@ -76,7 +83,7 @@ public class GeoPolygonFilterBuilder extends BaseFilterBuilder {
|
||||||
builder.startObject(name);
|
builder.startObject(name);
|
||||||
builder.startArray("points");
|
builder.startArray("points");
|
||||||
for (GeoPolygonFilter.Point point : points) {
|
for (GeoPolygonFilter.Point point : points) {
|
||||||
builder.startArray().value(point.lat).value(point.lon).endArray();
|
builder.startArray().value(point.lon).value(point.lat).endArray();
|
||||||
}
|
}
|
||||||
builder.endArray();
|
builder.endArray();
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
|
@ -95,9 +95,9 @@ public class GeoPolygonFilterParser extends AbstractIndexComponent implements XC
|
||||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||||
GeoPolygonFilter.Point point = new GeoPolygonFilter.Point();
|
GeoPolygonFilter.Point point = new GeoPolygonFilter.Point();
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
point.lat = parser.doubleValue();
|
|
||||||
token = parser.nextToken();
|
|
||||||
point.lon = parser.doubleValue();
|
point.lon = parser.doubleValue();
|
||||||
|
token = parser.nextToken();
|
||||||
|
point.lat = parser.doubleValue();
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,7 +232,7 @@ public class GeoDistanceFacetBuilder extends AbstractFacetBuilder {
|
||||||
if (geohash != null) {
|
if (geohash != null) {
|
||||||
builder.field(fieldName, geohash);
|
builder.field(fieldName, geohash);
|
||||||
} else {
|
} else {
|
||||||
builder.startArray(fieldName).value(lat).value(lon).endArray();
|
builder.startArray(fieldName).value(lon).value(lat).endArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valueFieldName != null) {
|
if (valueFieldName != null) {
|
||||||
|
|
|
@ -93,10 +93,10 @@ public class GeoDistanceFacetProcessor extends AbstractComponent implements Face
|
||||||
entries.add(new GeoDistanceFacet.Entry(from, to, 0, 0));
|
entries.add(new GeoDistanceFacet.Entry(from, to, 0, 0));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
token = parser.nextToken();
|
|
||||||
lat = parser.doubleValue();
|
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
lon = parser.doubleValue();
|
lon = parser.doubleValue();
|
||||||
|
token = parser.nextToken();
|
||||||
|
lat = parser.doubleValue();
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class GeoDistanceSortBuilder extends SortBuilder {
|
||||||
if (geohash != null) {
|
if (geohash != null) {
|
||||||
builder.field(fieldName, geohash);
|
builder.field(fieldName, geohash);
|
||||||
} else {
|
} else {
|
||||||
builder.startArray(fieldName).value(lat).value(lon).endArray();
|
builder.startArray(fieldName).value(lon).value(lat).endArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unit != null) {
|
if (unit != null) {
|
||||||
|
|
|
@ -52,10 +52,10 @@ public class GeoDistanceSortParser implements SortParser {
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
currentName = parser.currentName();
|
currentName = parser.currentName();
|
||||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||||
token = parser.nextToken();
|
|
||||||
lat = parser.doubleValue();
|
|
||||||
token = parser.nextToken();
|
token = parser.nextToken();
|
||||||
lon = parser.doubleValue();
|
lon = parser.doubleValue();
|
||||||
|
token = parser.nextToken();
|
||||||
|
lat = parser.doubleValue();
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,7 +185,7 @@ public class LatLonMappingGeoPointTests {
|
||||||
assertThat(doc.doc().get("point"), notNullValue());
|
assertThat(doc.doc().get("point"), notNullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testLatLonArray() throws Exception {
|
@Test public void testLonLatArray() throws Exception {
|
||||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||||
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).endObject().endObject()
|
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).endObject().endObject()
|
||||||
.endObject().endObject().string();
|
.endObject().endObject().string();
|
||||||
|
@ -194,7 +194,7 @@ public class LatLonMappingGeoPointTests {
|
||||||
|
|
||||||
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||||
.startObject()
|
.startObject()
|
||||||
.startArray("point").value(1.2).value(1.3).endArray()
|
.startArray("point").value(1.3).value(1.2).endArray()
|
||||||
.endObject()
|
.endObject()
|
||||||
.copiedBytes());
|
.copiedBytes());
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ public class LatLonMappingGeoPointTests {
|
||||||
assertThat(doc.doc().get("point"), equalTo("1.2,1.3"));
|
assertThat(doc.doc().get("point"), equalTo("1.2,1.3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testLatLonArrayStored() throws Exception {
|
@Test public void testLonLatArrayStored() throws Exception {
|
||||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||||
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("store", "yes").endObject().endObject()
|
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("store", "yes").endObject().endObject()
|
||||||
.endObject().endObject().string();
|
.endObject().endObject().string();
|
||||||
|
@ -214,7 +214,7 @@ public class LatLonMappingGeoPointTests {
|
||||||
|
|
||||||
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||||
.startObject()
|
.startObject()
|
||||||
.startArray("point").value(1.2).value(1.3).endArray()
|
.startArray("point").value(1.3).value(1.2).endArray()
|
||||||
.endObject()
|
.endObject()
|
||||||
.copiedBytes());
|
.copiedBytes());
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ public class LatLonMappingGeoPointTests {
|
||||||
assertThat(doc.doc().get("point"), equalTo("1.2,1.3"));
|
assertThat(doc.doc().get("point"), equalTo("1.2,1.3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testLatLonArrayArrayStored() throws Exception {
|
@Test public void testLonLatArrayArrayStored() throws Exception {
|
||||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||||
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("store", "yes").endObject().endObject()
|
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("store", "yes").endObject().endObject()
|
||||||
.endObject().endObject().string();
|
.endObject().endObject().string();
|
||||||
|
@ -235,8 +235,8 @@ public class LatLonMappingGeoPointTests {
|
||||||
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||||
.startObject()
|
.startObject()
|
||||||
.startArray("point")
|
.startArray("point")
|
||||||
.startArray().value(1.2).value(1.3).endArray()
|
.startArray().value(1.3).value(1.2).endArray()
|
||||||
.startArray().value(1.4).value(1.5).endArray()
|
.startArray().value(1.5).value(1.4).endArray()
|
||||||
.endArray()
|
.endArray()
|
||||||
.endObject()
|
.endObject()
|
||||||
.copiedBytes());
|
.copiedBytes());
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
"filter" : {
|
"filter" : {
|
||||||
"geo_bounding_box" : {
|
"geo_bounding_box" : {
|
||||||
"person.location" : {
|
"person.location" : {
|
||||||
"top_left" : [40, -70],
|
"top_left" : [-70, 40],
|
||||||
"bottom_right" : [30, -80]
|
"bottom_right" : [-80, 30]
|
||||||
},
|
},
|
||||||
"_name" : "test"
|
"_name" : "test"
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
"filter" : {
|
"filter" : {
|
||||||
"geo_bounding_box" : {
|
"geo_bounding_box" : {
|
||||||
"person.location" : {
|
"person.location" : {
|
||||||
"top_left" : [40, -70],
|
"top_left" : [-70, 40],
|
||||||
"bottom_right" : [30, -80]
|
"bottom_right" : [-80, 30]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
"filter" : {
|
"filter" : {
|
||||||
"geo_distance" : {
|
"geo_distance" : {
|
||||||
"distance" : "12mi",
|
"distance" : "12mi",
|
||||||
"person.location" : [40, -70]
|
"person.location" : [-70, 40]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
"geo_polygon" : {
|
"geo_polygon" : {
|
||||||
"person.location" : {
|
"person.location" : {
|
||||||
"points" : [
|
"points" : [
|
||||||
[40, -70],
|
[-70, 40],
|
||||||
[30, -80],
|
[-80, 30],
|
||||||
[20, -90]
|
[-90, 20]
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"_name" : "test"
|
"_name" : "test"
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
"geo_polygon" : {
|
"geo_polygon" : {
|
||||||
"person.location" : {
|
"person.location" : {
|
||||||
"points" : [
|
"points" : [
|
||||||
[40, -70],
|
[-70, 40],
|
||||||
[30, -80],
|
[-80, 30],
|
||||||
[20, -90]
|
[-90, 20]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue