How to Run an Atlas Search Compound Geo JSON Query
On this page
This tutorial describes how to create an index on the
listingsAndReviews
collection in the sample_airbnb
database
and run a query that returns documents with the
name
, address
, and property_type
for each property within the specified polygon defined using coordinates
.
This tutorial takes you through the following steps:
Set up an Atlas Search index on the
address
field in thesample_airbnb.listingsAndReviews
collection.Run a query that returns 10 documents with the
name
,address
, andproperty_type
of each property within the specified geographiccoordinates
. Atlas Search results reflect a preference for properties of typecondominium
, and each document in the result is assigned a relevancescore
, returned in order from highest to lowest.
Before you begin, ensure that your Atlas cluster meets the requirements described in the Prerequisites.
Required Access
To create an Atlas Search index, you must have Project Data Access Admin
or higher access to the project.
Create the Atlas Search Index
In this section, you will create an Atlas Search index on the address
field
in the sample_airbnb.listingsAndReviews
collection.
Navigate to the Atlas Search page for your project.
If it is not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.
If it is not already displayed, select your desired project from the Projects menu in the navigation bar.
Click your cluster's name.
Click the Search tab.
Enter the Index Name, and set the Database and Collection.
In the Index Name field, enter
geo-json-tutorial
.Note
If you name your index
default
, you don't need to specify anindex
parameter when using the $search pipeline stage. Otherwise, you must specify the index name using theindex
parameter.In the Database and Collection section, find the
sample_airbnb
database, and select thelistingsAndReviews
collection.
Define an index on the address
field.
You can use the Visual Editor or the JSON Editor in the Atlas user interface to create the index. The following index definition specifies that Atlas Search must index:
All of the fields in the collection automatically.
The
address.location
field of adocument
as typegeo
.
Run a Combined Geo, Number, and Text Fields Query
➤ Use the Select your language drop-down menu on this page to set the language of the examples in this section.
In this section, you will run a query that returns 10 documents with the
name
, address
, and property_type
for each property within the specified
geographic coordinates
.
A field specifying each documents score
is also returned,
and results are ordered with a preference for
properties of type condominium
.