Run a Geospatial Search Query with the Capella UI

  • Capella Operational
  • how-to
    +
    Search for geospatial data in your Couchbase Capella 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 cluster. For more information about how to change Services on your cluster, see Modify a Paid Cluster.

    • You have a bucket with scopes and collections in your cluster. For more information, see Manage Buckets.

    • You have documents in your cluster that contain geospatial data.

    • You have logged in to the Couchbase Capella UI.

    Procedure

    Create a Search Index with a Geospatial Type Mapping

    To create the Search index in the Capella UI with Advanced Mode:

    1. On the Operational Clusters page, select the cluster where you want to create a Search index.

    2. Go to Data Tools  Search.

    3. Click Create Search Index.

    4. Click the Advanced Mode toggle.

    5. 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.

    6. Under Type Mappings, in the Bucket list, select the bucket where you want to create your Search index.

    7. In the Scope list, select the scope where you want to create the index.

    8. In the Filter by collection or field field, enter the name of the collection you want to search.

      1. When the collection appears, click the collection name.

      2. Click Add.

    9. In the Filter by collection or field field, enter the name of the field that contains the geospatial data you want to search.

      This field should contain child fields with lat and long data.

      1. When the field appears, click the field name.

      2. Click the Child toggle.

      3. In the Type list, select Geopoint.

      4. Select Index this field.

      5. Select Include in _all field.

      6. Click Add.

    10. Click Create Index

    Run a Geospatial Search Query

    To run a Search query against the Search index from the Capella UI:

    1. Next to your geospatial type mapping Search index, click Search.

    2. 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 cluster’s search, see Use Autocomplete with the Search Service.