Run a Geospatial Search Query with the Web Console
- how-to
Search for geospatial data in your Couchbase database with a compatible Search index and the Couchbase Server Web Console.
Prerequisites
-
You’ve deployed the Search Service on a node in your database.
-
You have a bucket with scopes and collections in your database.
-
Your user account has the Search Admin role for the bucket where you want to create the index.
-
You’ve logged in to the Couchbase Server Web Console.
Procedure
To run a geospatial Search query, create a Search index with a geospatial type mapping.
Create a Search Index with a Geospatial Type Mapping
To create the Search index from the Web Console:
-
Go to Search.
-
Click Add Index.
-
In the Index Name field, enter a name for the index.
Your index name must start with an alphabetic character (a-z or A-Z). It can only contain alphanumeric characters (a-z, A-Z, or 0-9), hyphens (-), or underscores (_). -
In the Bucket list, select the bucket where you want to create the index.
-
Create a Type Mapping on the scope and collection in your database that you want to search.
-
Create a Child Field on the new type mapping with the following settings:
-
In the Field field, enter the name of the field in your documents that contains the geospatial data you want to search.
-
In the Type list, select geopoint.
-
Select Index.
-
Select Include in _all field.
-
-
Click Submit.
-
Click Create Index.
Run a Geospatial Search Query
To run a Search query against the Search index from the Web Console:
-
Go to Search.
-
Click the index where you want to run a search.
-
In the Search this index field, enter a search query.
For example, the following query searches a geospatial field,
geo
, for any locations within a 100 mile radius of the coordinates-2.235143, 53.482358
:{ "from": 0, "size": 10, "query": { "location": { "lon": -2.235143, "lat": 53.482358 }, "distance": "100mi", "field": "geo" }, "sort": [ { "by": "geo_distance", "field": "geo", "unit": "mi", "location": { "lon": -2.235143, "lat": 53.482358 } } ] }
Next Steps
You can customize your Search index to improve search results and performance.
If you want to add autocomplete to your database’s search, see Use Autocomplete with the Search Service.