Package org.elasticsearch.index.query
Class GeoBoundingBoxQueryBuilder
- java.lang.Object
-
- org.elasticsearch.index.query.AbstractQueryBuilder<GeoBoundingBoxQueryBuilder>
-
- org.elasticsearch.index.query.GeoBoundingBoxQueryBuilder
-
- All Implemented Interfaces:
NamedWriteable
,Writeable
,ToXContent
,ToXContentObject
,QueryBuilder
,Rewriteable<QueryBuilder>
public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder<GeoBoundingBoxQueryBuilder>
Creates a Lucene query that will filter for all documents that lie within the specified bounding box. This query can only operate on fields of type geo_point that have latitude and longitude enabled.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
DEFAULT_IGNORE_UNMAPPED
The default value for ignore_unmapped.static GeoExecType
DEFAULT_TYPE
Default type for executing this query (memory as of this writing).static java.lang.String
NAME
-
Fields inherited from class org.elasticsearch.index.query.AbstractQueryBuilder
boost, BOOST_FIELD, DEFAULT_BOOST, NAME_FIELD, queryName
-
Fields inherited from interface org.elasticsearch.index.query.Rewriteable
MAX_REWRITE_ROUNDS
-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Constructor Description GeoBoundingBoxQueryBuilder(java.lang.String fieldName)
Create new bounding box query.GeoBoundingBoxQueryBuilder(StreamInput in)
Read from a stream.
-
Method Summary
Modifier and Type Method Description GeoPoint
bottomRight()
Returns the bottom right corner of the bounding box.protected boolean
doEquals(GeoBoundingBoxQueryBuilder other)
Indicates whether some otherQueryBuilder
object of the same type is "equal to" this one.protected int
doHashCode()
org.apache.lucene.search.Query
doToQuery(QueryShardContext context)
protected void
doWriteTo(StreamOutput out)
protected void
doXContent(XContentBuilder builder, ToXContent.Params params)
java.lang.String
fieldName()
Returns the name of the field to base the bounding box computation on.static GeoBoundingBoxQueryBuilder
fromXContent(XContentParser parser)
GeoValidationMethod
getValidationMethod()
Returns geo coordinate validation method to use.java.lang.String
getWriteableName()
Returns the name of the writeable objectboolean
ignoreUnmapped()
Gets whether the query builder will ignore unmapped fields (and run aMatchNoDocsQuery
in place of this query) or throw an exception if the field is unmapped.GeoBoundingBoxQueryBuilder
ignoreUnmapped(boolean ignoreUnmapped)
Sets whether the query builder should ignore unmapped fields (and run aMatchNoDocsQuery
in place of this query) or throw an exception if the field is unmapped.static double[]
parseBoundingBox(XContentParser parser)
Parses the bounding box and returns bottom, top, left, right coordinatesGeoBoundingBoxQueryBuilder
setCorners(double top, double left, double bottom, double right)
Adds top left point.GeoBoundingBoxQueryBuilder
setCorners(java.lang.String geohash)
Adds points from a single geohash.GeoBoundingBoxQueryBuilder
setCorners(java.lang.String topLeft, java.lang.String bottomRight)
Adds points.GeoBoundingBoxQueryBuilder
setCorners(GeoPoint topLeft, GeoPoint bottomRight)
Adds points.GeoBoundingBoxQueryBuilder
setCornersOGC(java.lang.String bottomLeft, java.lang.String topRight)
Adds corners in OGC standard bbox/ envelop format.GeoBoundingBoxQueryBuilder
setCornersOGC(GeoPoint bottomLeft, GeoPoint topRight)
Adds corners in OGC standard bbox/ envelop format.GeoBoundingBoxQueryBuilder
setValidationMethod(GeoValidationMethod method)
Specify whether or not to ignore validation errors of bounding boxes.GeoPoint
topLeft()
Returns the top left corner of the bounding box.GeoExecType
type()
Returns the execution type of the geo bounding box.GeoBoundingBoxQueryBuilder
type(java.lang.String type)
For BWC: Parse type from type name.GeoBoundingBoxQueryBuilder
type(GeoExecType type)
Sets the type of executing of the geo bounding box.-
Methods inherited from class org.elasticsearch.index.query.AbstractQueryBuilder
addValidationError, boost, boost, checkNegativeBoost, declareStandardFields, doRewrite, equals, extractInnerHitBuilders, getName, hashCode, parseInnerQueryBuilder, printBoostAndQueryName, queryName, queryName, requireValue, rewrite, throwParsingExceptionOnMultipleFields, toFilter, toQuery, toString, toString, toXContent, writeTo
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentObject
isFragment
-
-
-
-
Field Detail
-
NAME
public static final java.lang.String NAME
- See Also:
- Constant Field Values
-
DEFAULT_TYPE
public static final GeoExecType DEFAULT_TYPE
Default type for executing this query (memory as of this writing).
-
DEFAULT_IGNORE_UNMAPPED
public static final boolean DEFAULT_IGNORE_UNMAPPED
The default value for ignore_unmapped.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GeoBoundingBoxQueryBuilder
public GeoBoundingBoxQueryBuilder(java.lang.String fieldName)
Create new bounding box query.- Parameters:
fieldName
- name of index field containing geo coordinates to operate on.
-
GeoBoundingBoxQueryBuilder
public GeoBoundingBoxQueryBuilder(StreamInput in) throws java.io.IOException
Read from a stream.- Throws:
java.io.IOException
-
-
Method Detail
-
doWriteTo
protected void doWriteTo(StreamOutput out) throws java.io.IOException
- Specified by:
doWriteTo
in classAbstractQueryBuilder<GeoBoundingBoxQueryBuilder>
- Throws:
java.io.IOException
-
setCorners
public GeoBoundingBoxQueryBuilder setCorners(double top, double left, double bottom, double right)
Adds top left point.- Parameters:
top
- The top latitudeleft
- The left longitudebottom
- The bottom latituderight
- The right longitude
-
setCorners
public GeoBoundingBoxQueryBuilder setCorners(GeoPoint topLeft, GeoPoint bottomRight)
Adds points.- Parameters:
topLeft
- topLeft point to add.bottomRight
- bottomRight point to add.
-
setCorners
public GeoBoundingBoxQueryBuilder setCorners(java.lang.String geohash)
Adds points from a single geohash.- Parameters:
geohash
- The geohash for computing the bounding box.
-
setCorners
public GeoBoundingBoxQueryBuilder setCorners(java.lang.String topLeft, java.lang.String bottomRight)
Adds points.- Parameters:
topLeft
- topLeft point to add as geohash.bottomRight
- bottomRight point to add as geohash.
-
topLeft
public GeoPoint topLeft()
Returns the top left corner of the bounding box.
-
bottomRight
public GeoPoint bottomRight()
Returns the bottom right corner of the bounding box.
-
setCornersOGC
public GeoBoundingBoxQueryBuilder setCornersOGC(GeoPoint bottomLeft, GeoPoint topRight)
Adds corners in OGC standard bbox/ envelop format.- Parameters:
bottomLeft
- bottom left corner of bounding box.topRight
- top right corner of bounding box.
-
setCornersOGC
public GeoBoundingBoxQueryBuilder setCornersOGC(java.lang.String bottomLeft, java.lang.String topRight)
Adds corners in OGC standard bbox/ envelop format.- Parameters:
bottomLeft
- bottom left corner geohash.topRight
- top right corner geohash.
-
setValidationMethod
public GeoBoundingBoxQueryBuilder setValidationMethod(GeoValidationMethod method)
Specify whether or not to ignore validation errors of bounding boxes. Can only be set if coerce set to false, otherwise calling this method has no effect.
-
getValidationMethod
public GeoValidationMethod getValidationMethod()
Returns geo coordinate validation method to use.
-
type
public GeoBoundingBoxQueryBuilder type(GeoExecType type)
Sets the type of executing of the geo bounding box. Can be either `memory` or `indexed`. Defaults to `memory`.
-
type
public GeoBoundingBoxQueryBuilder type(java.lang.String type)
For BWC: Parse type from type name.
-
type
public GeoExecType type()
Returns the execution type of the geo bounding box.
-
fieldName
public java.lang.String fieldName()
Returns the name of the field to base the bounding box computation on.
-
ignoreUnmapped
public GeoBoundingBoxQueryBuilder ignoreUnmapped(boolean ignoreUnmapped)
Sets whether the query builder should ignore unmapped fields (and run aMatchNoDocsQuery
in place of this query) or throw an exception if the field is unmapped.
-
ignoreUnmapped
public boolean ignoreUnmapped()
Gets whether the query builder will ignore unmapped fields (and run aMatchNoDocsQuery
in place of this query) or throw an exception if the field is unmapped.
-
doToQuery
public org.apache.lucene.search.Query doToQuery(QueryShardContext context)
- Specified by:
doToQuery
in classAbstractQueryBuilder<GeoBoundingBoxQueryBuilder>
-
doXContent
protected void doXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
doXContent
in classAbstractQueryBuilder<GeoBoundingBoxQueryBuilder>
- Throws:
java.io.IOException
-
fromXContent
public static GeoBoundingBoxQueryBuilder fromXContent(XContentParser parser) throws java.io.IOException
- Throws:
java.io.IOException
-
doEquals
protected boolean doEquals(GeoBoundingBoxQueryBuilder other)
Description copied from class:AbstractQueryBuilder
Indicates whether some otherQueryBuilder
object of the same type is "equal to" this one.- Specified by:
doEquals
in classAbstractQueryBuilder<GeoBoundingBoxQueryBuilder>
-
doHashCode
protected int doHashCode()
- Specified by:
doHashCode
in classAbstractQueryBuilder<GeoBoundingBoxQueryBuilder>
-
getWriteableName
public java.lang.String getWriteableName()
Description copied from interface:NamedWriteable
Returns the name of the writeable object
-
parseBoundingBox
public static double[] parseBoundingBox(XContentParser parser) throws java.io.IOException, ElasticsearchParseException
Parses the bounding box and returns bottom, top, left, right coordinates- Throws:
java.io.IOException
ElasticsearchParseException
-
-