change the format of bounding box filter to conform more to the "field_name" : { ... } structure
This commit is contained in:
parent
91c256361e
commit
39f344c11e
|
@ -71,7 +71,7 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
|
||||||
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
builder.startObject(GeoBoundingBoxFilterParser.NAME);
|
builder.startObject(GeoBoundingBoxFilterParser.NAME);
|
||||||
|
|
||||||
builder.field("field", name);
|
builder.startObject(name);
|
||||||
if (topLeftGeohash != null) {
|
if (topLeftGeohash != null) {
|
||||||
builder.field("top_left", topLeftGeohash);
|
builder.field("top_left", topLeftGeohash);
|
||||||
} else if (topLeft != null) {
|
} else if (topLeft != null) {
|
||||||
|
@ -87,6 +87,7 @@ public class GeoBoundingBoxFilterBuilder extends BaseFilterBuilder {
|
||||||
} 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");
|
||||||
}
|
}
|
||||||
|
builder.endObject();
|
||||||
|
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,14 +53,20 @@ public class GeoBoundingBoxFilterParser extends AbstractIndexComponent implement
|
||||||
@Override public Filter parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
@Override public Filter parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
|
||||||
XContentParser parser = parseContext.parser();
|
XContentParser parser = parseContext.parser();
|
||||||
|
|
||||||
|
XContentParser.Token token = parser.nextToken();
|
||||||
|
assert token == XContentParser.Token.FIELD_NAME;
|
||||||
|
String latFieldName = parser.currentName() + XContentGeoPointFieldMapper.Names.LAT_SUFFIX;
|
||||||
|
String lonFieldName = parser.currentName() + XContentGeoPointFieldMapper.Names.LON_SUFFIX;
|
||||||
|
|
||||||
|
// now, we move after the field name, which starts the object
|
||||||
|
token = parser.nextToken();
|
||||||
|
assert token == XContentParser.Token.START_OBJECT;
|
||||||
|
|
||||||
|
|
||||||
GeoBoundingBoxFilter.Point topLeft = new GeoBoundingBoxFilter.Point();
|
GeoBoundingBoxFilter.Point topLeft = new GeoBoundingBoxFilter.Point();
|
||||||
GeoBoundingBoxFilter.Point bottomRight = new GeoBoundingBoxFilter.Point();
|
GeoBoundingBoxFilter.Point bottomRight = new GeoBoundingBoxFilter.Point();
|
||||||
|
|
||||||
String latFieldName = null;
|
|
||||||
String lonFieldName = null;
|
|
||||||
|
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
XContentParser.Token token;
|
|
||||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||||
if (token == XContentParser.Token.FIELD_NAME) {
|
if (token == XContentParser.Token.FIELD_NAME) {
|
||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
|
|
|
@ -5,9 +5,10 @@
|
||||||
},
|
},
|
||||||
"filter" : {
|
"filter" : {
|
||||||
"geo_bounding_box" : {
|
"geo_bounding_box" : {
|
||||||
"field" : "person.location",
|
"person.location" : {
|
||||||
"top_left" : [40, -70],
|
"top_left" : [40, -70],
|
||||||
"bottom_right" : [30, -80]
|
"bottom_right" : [30, -80]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,15 @@
|
||||||
},
|
},
|
||||||
"filter" : {
|
"filter" : {
|
||||||
"geo_bounding_box" : {
|
"geo_bounding_box" : {
|
||||||
"field" : "person.location",
|
"person.location" : {
|
||||||
"top_left" : {
|
"top_left" : {
|
||||||
"lat" : 40,
|
"lat" : 40,
|
||||||
"lon" : -70
|
"lon" : -70
|
||||||
},
|
},
|
||||||
"bottom_right" : {
|
"bottom_right" : {
|
||||||
"lat" : 30,
|
"lat" : 30,
|
||||||
"lon" : -80
|
"lon" : -80
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,10 @@
|
||||||
},
|
},
|
||||||
"filter" : {
|
"filter" : {
|
||||||
"geo_bounding_box" : {
|
"geo_bounding_box" : {
|
||||||
"field" : "person.location",
|
"person.location" : {
|
||||||
"top_left" : "40, -70",
|
"top_left" : "40, -70",
|
||||||
"bottom_right" : "30, -80"
|
"bottom_right" : "30, -80"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,10 @@
|
||||||
},
|
},
|
||||||
"filter" : {
|
"filter" : {
|
||||||
"geo_bounding_box" : {
|
"geo_bounding_box" : {
|
||||||
"field" : "person.location",
|
"person.location" : {
|
||||||
"top_left" : "drn5x1g8cu2y",
|
"top_left" : "drn5x1g8cu2y",
|
||||||
"bottom_right" : "30, -80"
|
"bottom_right" : "30, -80"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue