Run a Geospatial Search Query with the Capella UI
- Capella Operational
- how-to
Search for geospatial data in your Couchbase Capella operational cluster with a compatible Search index and the Capella UI.
For more information about how the Search Service scores documents in search results, see Scoring for Search Queries.
Prerequisites
-
You have the Search Service enabled on a node in your operational cluster. For more information about how to change Services on your operational cluster, see Modify a Paid Cluster.
-
You have a bucket with scopes and collections in your operational cluster. For more information, see Manage Buckets.
-
You have documents in your operational cluster that contain geospatial data.
-
You have logged in to the Couchbase Capella UI.
Procedure
To run a geospatial Search query, create a Search index with a geospatial type mapping in Advanced Mode.
Create a Search Index with a Geospatial Type Mapping
To create the Search index in the Capella UI with Advanced Mode:
-
On the Operational Clusters page, select the operational cluster where you want to create a Search index.
-
Go to
. -
Click Create Search Index.
-
In the Index Name field, enter a name for the Search 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 (_).
For Couchbase Server version 7.6 and later, your index name must be unique inside your selected bucket and scope. You cannot have 2 indexes with the same name inside the same bucket and scope.
-
In the Bucket and Scope lists, choose the bucket and scope where you want to create your Search index. This bucket and scope should contain the collection and documents that have your geospatial data.
-
In your document schema, expand the collection that holds the documents with your geospatial data.
-
Click the name of the field that holds your geospatial data.
-
In the Type list, select Geopoint.
-
Select Include in search results.
-
Select Support field agnostic search.
-
Click Add To Index.
-
Click Create Index.
Run a Geospatial Search Query
To run a Search query against the Search index from the Capella UI:
-
Next to your geospatial type mapping Search index, click Search.
-
In the Search field, enter a search query for geospatial data.
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
For more information about the different features you can add to your Search index to improve performance and search results, see Search Index Features.
If you want to add autocomplete to your operational cluster’s search, see Use Autocomplete with the Search Service.