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) {
|
||||
token = context.parser().nextToken();
|
||||
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) {
|
||||
token = context.parser().nextToken();
|
||||
Double lat = context.parser().doubleValue();
|
||||
token = context.parser().nextToken();
|
||||
Double lon = context.parser().doubleValue();
|
||||
token = context.parser().nextToken();
|
||||
Double lat = context.parser().doubleValue();
|
||||
while ((token = context.parser().nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
|
||||
}
|
||||
|
@ -242,9 +242,9 @@ public class GeoPointFieldMapper implements XContentMapper, ArrayValueMapperPars
|
|||
} else {
|
||||
// its an array of other possible values
|
||||
if (token == XContentParser.Token.VALUE_NUMBER) {
|
||||
Double lat = context.parser().doubleValue();
|
||||
token = context.parser().nextToken();
|
||||
Double lon = context.parser().doubleValue();
|
||||
token = context.parser().nextToken();
|
||||
Double lat = context.parser().doubleValue();
|
||||
while ((token = context.parser().nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
|
||||
}
|
||||
|
|
|
@ -48,6 +48,12 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds top left point.
|
||||
*
|
||||
* @param lat The latitude
|
||||
* @param lon The longitude
|
||||
*/
|
||||
public GeoBoundingBoxFilterBuilder topLeft(double lat, double lon) {
|
||||
topLeft = new GeoBoundingBoxFilter.Point();
|
||||
topLeft.lat = lat;
|
||||
|
@ -55,6 +61,12 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds bottom right point.
|
||||
*
|
||||
* @param lat The latitude
|
||||
* @param lon The longitude
|
||||
*/
|
||||
public GeoBoundingBoxFilterBuilder bottomRight(double lat, double lon) {
|
||||
bottomRight = new GeoBoundingBoxFilter.Point();
|
||||
bottomRight.lat = lat;
|
||||
|
@ -95,7 +107,7 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
|
|||
if (topLeftGeohash != null) {
|
||||
builder.field("top_left", topLeftGeohash);
|
||||
} 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 {
|
||||
throw new QueryBuilderException("geo_bounding_box requires 'top_left' to be set");
|
||||
}
|
||||
|
@ -103,7 +115,7 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
|
|||
if (bottomRightGeohash != null) {
|
||||
builder.field("bottom_right", bottomRightGeohash);
|
||||
} 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 {
|
||||
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) {
|
||||
token = parser.nextToken();
|
||||
point.lat = parser.doubleValue();
|
||||
token = parser.nextToken();
|
||||
point.lon = parser.doubleValue();
|
||||
token = parser.nextToken();
|
||||
point.lat = parser.doubleValue();
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ public class GeoDistanceFilterBuilder extends BaseFilterBuilder {
|
|||
if (geohash != null) {
|
||||
builder.field(name, geohash);
|
||||
} else {
|
||||
builder.startArray(name).value(lat).value(lon).endArray();
|
||||
builder.startArray(name).value(lon).value(lat).endArray();
|
||||
}
|
||||
builder.field("distance", distance);
|
||||
if (geoDistance != null) {
|
||||
|
|
|
@ -81,10 +81,10 @@ public class GeoDistanceFilterParser extends AbstractIndexComponent implements X
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
token = parser.nextToken();
|
||||
lat = parser.doubleValue();
|
||||
token = parser.nextToken();
|
||||
lon = parser.doubleValue();
|
||||
token = parser.nextToken();
|
||||
lat = parser.doubleValue();
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
|
||||
}
|
||||
|
|
|
@ -44,6 +44,13 @@ public class GeoPolygonFilterBuilder extends BaseFilterBuilder {
|
|||
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) {
|
||||
points.add(new GeoPolygonFilter.Point(lat, lon));
|
||||
return this;
|
||||
|
@ -76,7 +83,7 @@ public class GeoPolygonFilterBuilder extends BaseFilterBuilder {
|
|||
builder.startObject(name);
|
||||
builder.startArray("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.endObject();
|
||||
|
|
|
@ -95,9 +95,9 @@ public class GeoPolygonFilterParser extends AbstractIndexComponent implements XC
|
|||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
GeoPolygonFilter.Point point = new GeoPolygonFilter.Point();
|
||||
token = parser.nextToken();
|
||||
point.lat = parser.doubleValue();
|
||||
token = parser.nextToken();
|
||||
point.lon = parser.doubleValue();
|
||||
token = parser.nextToken();
|
||||
point.lat = parser.doubleValue();
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
|
||||
}
|
||||
|
|
|
@ -232,7 +232,7 @@ public class GeoDistanceFacetBuilder extends AbstractFacetBuilder {
|
|||
if (geohash != null) {
|
||||
builder.field(fieldName, geohash);
|
||||
} else {
|
||||
builder.startArray(fieldName).value(lat).value(lon).endArray();
|
||||
builder.startArray(fieldName).value(lon).value(lat).endArray();
|
||||
}
|
||||
|
||||
if (valueFieldName != null) {
|
||||
|
|
|
@ -93,10 +93,10 @@ public class GeoDistanceFacetProcessor extends AbstractComponent implements Face
|
|||
entries.add(new GeoDistanceFacet.Entry(from, to, 0, 0));
|
||||
}
|
||||
} else {
|
||||
token = parser.nextToken();
|
||||
lat = parser.doubleValue();
|
||||
token = parser.nextToken();
|
||||
lon = parser.doubleValue();
|
||||
token = parser.nextToken();
|
||||
lat = parser.doubleValue();
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ public class GeoDistanceSortBuilder extends SortBuilder {
|
|||
if (geohash != null) {
|
||||
builder.field(fieldName, geohash);
|
||||
} else {
|
||||
builder.startArray(fieldName).value(lat).value(lon).endArray();
|
||||
builder.startArray(fieldName).value(lon).value(lat).endArray();
|
||||
}
|
||||
|
||||
if (unit != null) {
|
||||
|
|
|
@ -52,10 +52,10 @@ public class GeoDistanceSortParser implements SortParser {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_ARRAY) {
|
||||
token = parser.nextToken();
|
||||
lat = parser.doubleValue();
|
||||
token = parser.nextToken();
|
||||
lon = parser.doubleValue();
|
||||
token = parser.nextToken();
|
||||
lat = parser.doubleValue();
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
|
||||
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@ public class LatLonMappingGeoPointTests {
|
|||
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")
|
||||
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).endObject().endObject()
|
||||
.endObject().endObject().string();
|
||||
|
@ -194,7 +194,7 @@ public class LatLonMappingGeoPointTests {
|
|||
|
||||
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startArray("point").value(1.2).value(1.3).endArray()
|
||||
.startArray("point").value(1.3).value(1.2).endArray()
|
||||
.endObject()
|
||||
.copiedBytes());
|
||||
|
||||
|
@ -205,7 +205,7 @@ public class LatLonMappingGeoPointTests {
|
|||
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")
|
||||
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("store", "yes").endObject().endObject()
|
||||
.endObject().endObject().string();
|
||||
|
@ -214,7 +214,7 @@ public class LatLonMappingGeoPointTests {
|
|||
|
||||
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startArray("point").value(1.2).value(1.3).endArray()
|
||||
.startArray("point").value(1.3).value(1.2).endArray()
|
||||
.endObject()
|
||||
.copiedBytes());
|
||||
|
||||
|
@ -225,7 +225,7 @@ public class LatLonMappingGeoPointTests {
|
|||
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")
|
||||
.startObject("properties").startObject("point").field("type", "geo_point").field("lat_lon", true).field("store", "yes").endObject().endObject()
|
||||
.endObject().endObject().string();
|
||||
|
@ -235,8 +235,8 @@ public class LatLonMappingGeoPointTests {
|
|||
ParsedDocument doc = defaultMapper.parse("type", "1", XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startArray("point")
|
||||
.startArray().value(1.2).value(1.3).endArray()
|
||||
.startArray().value(1.4).value(1.5).endArray()
|
||||
.startArray().value(1.3).value(1.2).endArray()
|
||||
.startArray().value(1.5).value(1.4).endArray()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.copiedBytes());
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
"filter" : {
|
||||
"geo_bounding_box" : {
|
||||
"person.location" : {
|
||||
"top_left" : [40, -70],
|
||||
"bottom_right" : [30, -80]
|
||||
"top_left" : [-70, 40],
|
||||
"bottom_right" : [-80, 30]
|
||||
},
|
||||
"_name" : "test"
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
"filter" : {
|
||||
"geo_bounding_box" : {
|
||||
"person.location" : {
|
||||
"top_left" : [40, -70],
|
||||
"bottom_right" : [30, -80]
|
||||
"top_left" : [-70, 40],
|
||||
"bottom_right" : [-80, 30]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"filter" : {
|
||||
"geo_distance" : {
|
||||
"distance" : "12mi",
|
||||
"person.location" : [40, -70]
|
||||
"person.location" : [-70, 40]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
"geo_polygon" : {
|
||||
"person.location" : {
|
||||
"points" : [
|
||||
[40, -70],
|
||||
[30, -80],
|
||||
[20, -90]
|
||||
[-70, 40],
|
||||
[-80, 30],
|
||||
[-90, 20]
|
||||
]
|
||||
},
|
||||
"_name" : "test"
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
"geo_polygon" : {
|
||||
"person.location" : {
|
||||
"points" : [
|
||||
[40, -70],
|
||||
[30, -80],
|
||||
[20, -90]
|
||||
[-70, 40],
|
||||
[-80, 30],
|
||||
[-90, 20]
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue