Class GeoBoundingBoxQueryBuilder

All Implemented Interfaces:
NamedWriteable, Writeable, org.elasticsearch.common.xcontent.ToXContent, org.elasticsearch.common.xcontent.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.
  • Field Details

    • NAME

      public static final java.lang.String NAME
      See Also:
      Constant Field Values

      public static final GeoExecType DEFAULT_TYPE
      Default type for executing this query (memory as of this writing).

      public static final boolean DEFAULT_IGNORE_UNMAPPED
      The default value for ignore_unmapped.
      See Also:
      Constant Field Values
  • Constructor Details

    • GeoBoundingBoxQueryBuilder

      public GeoBoundingBoxQueryBuilder​(java.lang.String fieldName)
      Create new bounding box query.
      fieldName - name of index field containing geo coordinates to operate on.
    • GeoBoundingBoxQueryBuilder

      public GeoBoundingBoxQueryBuilder​(StreamInput in) throws
      Read from a stream.
  • Method Details

    • doWriteTo

      protected void doWriteTo​(StreamOutput out) throws
      Specified by:
      doWriteTo in class AbstractQueryBuilder<GeoBoundingBoxQueryBuilder>
    • setCorners

      public GeoBoundingBoxQueryBuilder setCorners​(double top, double left, double bottom, double right)
      Adds top left point.
      top - The top latitude
      left - The left longitude
      bottom - The bottom latitude
      right - The right longitude
    • setCorners

      public GeoBoundingBoxQueryBuilder setCorners​(GeoPoint topLeft, GeoPoint bottomRight)
      Adds points.
      topLeft - topLeft point to add.
      bottomRight - bottomRight point to add.
    • setCorners

      public GeoBoundingBoxQueryBuilder setCorners​(java.lang.String geohash)
      Adds points from a single geohash.
      geohash - The geohash for computing the bounding box.
    • setCorners

      public GeoBoundingBoxQueryBuilder setCorners​(java.lang.String topLeft, java.lang.String bottomRight)
      Adds points.
      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.
      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.
      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 a MatchNoDocsQuery 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 a MatchNoDocsQuery in place of this query) or throw an exception if the field is unmapped.
    • doToQuery

      public doToQuery​(SearchExecutionContext context)
      Specified by:
      doToQuery in class AbstractQueryBuilder<GeoBoundingBoxQueryBuilder>
    • doXContent

      protected void doXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws
      Specified by:
      doXContent in class AbstractQueryBuilder<GeoBoundingBoxQueryBuilder>
    • fromXContent

      public static GeoBoundingBoxQueryBuilder fromXContent​(org.elasticsearch.common.xcontent.XContentParser parser) throws
    • doEquals

      protected boolean doEquals​(GeoBoundingBoxQueryBuilder other)
      Description copied from class: AbstractQueryBuilder
      Indicates whether some other QueryBuilder object of the same type is "equal to" this one.
      Specified by:
      doEquals in class AbstractQueryBuilder<GeoBoundingBoxQueryBuilder>
    • doHashCode

      protected int doHashCode()
      Specified by:
      doHashCode in class AbstractQueryBuilder<GeoBoundingBoxQueryBuilder>
    • getWriteableName

      public java.lang.String getWriteableName()
      Description copied from interface: NamedWriteable
      Returns the name of the writeable object