You can use the Atlas Search geo type to index geographic points and shape
coordinates. For this type, the indexed field must be a GeoJSON object. You can use the geoShape and
geoWithin operators to query indexed fields of type geo.
Atlas Search doesn't dynamically index
fields of type geo. You must use static mappings to index geo fields. You can
use the Visual Editor or the JSON Editor in the Atlas UI
to index fields of type geo.
Define the Index for the geo Type
To define the index for the geo type, choose your preferred
configuration method in the Atlas UI and then select the
database and collection.
Click Refine Your Index to configure your index.
In the Field Mappings section, click Add Field Mapping to open the Add Field Mapping window.
Click Customized Configuration.
Select the field to index from the Field Name dropdown.
Note
You can't index fields that contain the dollar (
$) sign at the start of the field name.Click the Data Type dropdown and select Geo.
Configure the field properties for the
geotype. To learn more, see Field Properties.Click Add.
The following is the JSON syntax for the geo type.
Replace the default index definition with the following. To learn more
about the fields, see Field Properties.
{ "mappings": { "dynamic": false, "fields": { "<field-name>": { "indexShapes": true|false, "type": "geo" } } } }
Configure geo Field Properties
The Atlas Search geo type takes the following parameters:
Option | Type | Necessity | Description | Default |
|---|---|---|---|---|
| string | Required | Human-readable label that identifies this field type.
UI value must be | |
| boolean | Optional | Flag that indicates whether to index shapes. By default, Atlas Search:
Value can be:
|
|
Try an Example for the geo Type
The following index definition example uses the sample_airbnb.listingsAndReviews collection. If you have the sample data already loaded on your cluster, you can use the Visual Editor or JSON Editor in the Atlas UI to configure the index. After you select your preferred configuration method, select the database and collection, and refine your index to add field mappings.
The following index definition indexes the address.location field as
the geo type to support queries against that field using the Atlas Search
geoShape and geoWithin operators.
In the Add Field Mapping window, select address.location from the Field Name dropdown.
Click the Data Type dropdown and select Geo.
Modify the Geo Properties to set the value for Index Shapes to
true.Click Add.
Replace the default index definition with the following index definition.
1 { 2 "mappings": { 3 "fields": { 4 "address": { 5 "type": "document", 6 "fields": { 7 "location": { 8 "indexShapes": true, 9 "type": "geo" 10 } 11 } 12 } 13 } 14 } 15 }
Learn More
To learn more about the operators you can use to query the geo type, see the following operator reference pages: