Geo (structured query)

isubiker edited this page Jan 31, 2012 · 6 revisions

Geospatial queries require the use geo indexes. Geo queries allow for the efficient fetching of documents based off of a point, circle, box or polygon. They require that the geo index name be specified along with a region definition to match against. The following query will find documents that fall within a circle with a radius of 10 miles located at the intersection of the prime meridian and the equator:

{
    "geo": "location", // The name references the name of the geo index as specified when creating
    "region": { "circle": {
        "radius": 10,
        "latitude": 0,
        "longitude": 0
    }}
}

<constraint>
    <geo>location</geo>
    <region>
        <circle>
            <radius>10</radius>
            <latitude>0</latitude>
            <longitude>0</longitude>
        </circle>
    </region>
</constraint>

Optional configuration:

  • weight (number, default: 1.0) - Configure how important or how heavily this geo term weighs in the query. The higher the number the more this geo term will contribute to the score of the document, thus appearing higher in the search results.
  • excludeBoundaries (boolean, default: false) - Points on boxes', circles', and polygons' boundaries are not counted as matching when set to true
  • excludeLatitudeBoundaries (boolean, default: false) - Points on boxes' latitude boundaries are not counted as matching when set to true
  • excludeLongitudeBoundaries (boolean, default: false) - Points on boxes' longitude boundaries are not counted as matching when set to true
  • excludeSouthBoundaries (boolean, default: false) - Points on the boxes' southern boundaries are not counted as matching when set to true
  • excludeWestBoundaries (boolean, default: false) - Points on the boxes' western boundaries are not counted as matching when set to true
  • excludeNorthBoundaries (boolean, default: false) - Points on the boxes' northern boundaries are not counted as matching when set to true
  • excludeEastBoundaries (boolean, default: false) - Points on the boxes' eastern boundaries are not counted as matching when set to true
  • excludeCircleBoundaries (boolean, default: false) - Points on circles' boundary are not counted as matching when set to true

Example

{
    "geo": "location", // The name references the name of the geo index as specified when creating
    "region": { "circle": {
        "radius": 10,
        "latitude": 0,
        "longitude": 0
    }},
    "excludeBoundaries": true
}

<constraint>
    <geo>location</geo>
    <region>
        <circle>
            <radius>10</radius>
            <latitude>0</latitude>
            <longitude>0</longitude>
        </circle>
    </region>
    <excludeBoundaries>true</excludeBoundaries>
</constraint>
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.