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 booleanDEFAULT_IGNORE_UNMAPPEDThe default value for ignore_unmapped.static GeoExecTypeDEFAULT_TYPEDefault type for executing this query (memory as of this writing).static java.lang.StringNAME-
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description GeoPointbottomRight()Returns the bottom right corner of the bounding box.protected booleandoEquals(GeoBoundingBoxQueryBuilder other)Indicates whether some otherQueryBuilderobject of the same type is "equal to" this one.protected intdoHashCode()org.apache.lucene.search.QuerydoToQuery(QueryShardContext context)protected voiddoWriteTo(StreamOutput out)protected voiddoXContent(XContentBuilder builder, ToXContent.Params params)java.lang.StringfieldName()Returns the name of the field to base the bounding box computation on.static GeoBoundingBoxQueryBuilderfromXContent(XContentParser parser)GeoValidationMethodgetValidationMethod()Returns geo coordinate validation method to use.java.lang.StringgetWriteableName()Returns the name of the writeable objectbooleanignoreUnmapped()Gets whether the query builder will ignore unmapped fields (and run aMatchNoDocsQueryin place of this query) or throw an exception if the field is unmapped.GeoBoundingBoxQueryBuilderignoreUnmapped(boolean ignoreUnmapped)Sets whether the query builder should ignore unmapped fields (and run aMatchNoDocsQueryin 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 coordinatesGeoBoundingBoxQueryBuildersetCorners(double top, double left, double bottom, double right)Adds top left point.GeoBoundingBoxQueryBuildersetCorners(java.lang.String geohash)Adds points from a single geohash.GeoBoundingBoxQueryBuildersetCorners(java.lang.String topLeft, java.lang.String bottomRight)Adds points.GeoBoundingBoxQueryBuildersetCorners(GeoPoint topLeft, GeoPoint bottomRight)Adds points.GeoBoundingBoxQueryBuildersetCornersOGC(java.lang.String bottomLeft, java.lang.String topRight)Adds corners in OGC standard bbox/ envelop format.GeoBoundingBoxQueryBuildersetCornersOGC(GeoPoint bottomLeft, GeoPoint topRight)Adds corners in OGC standard bbox/ envelop format.GeoBoundingBoxQueryBuildersetValidationMethod(GeoValidationMethod method)Specify whether or not to ignore validation errors of bounding boxes.GeoPointtopLeft()Returns the top left corner of the bounding box.GeoExecTypetype()Returns the execution type of the geo bounding box.GeoBoundingBoxQueryBuildertype(java.lang.String type)For BWC: Parse type from type name.GeoBoundingBoxQueryBuildertype(GeoExecType type)Sets the type of executing of the geo bounding box.-
Methods inherited from class org.elasticsearch.index.query.AbstractQueryBuilder
addValidationError, boost, boost, 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:
doWriteToin 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 aMatchNoDocsQueryin 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 aMatchNoDocsQueryin 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:
doToQueryin classAbstractQueryBuilder<GeoBoundingBoxQueryBuilder>
-
doXContent
protected void doXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
doXContentin 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:AbstractQueryBuilderIndicates whether some otherQueryBuilderobject of the same type is "equal to" this one.- Specified by:
doEqualsin classAbstractQueryBuilder<GeoBoundingBoxQueryBuilder>
-
doHashCode
protected int doHashCode()
- Specified by:
doHashCodein classAbstractQueryBuilder<GeoBoundingBoxQueryBuilder>
-
getWriteableName
public java.lang.String getWriteableName()
Description copied from interface:NamedWriteableReturns 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.IOExceptionElasticsearchParseException
-
-