Create a Synonym Collection and Documents

  • Capella Operational
  • how-to
  • Couchbase Server 8.0
    +
    Create a synonym collection and documents to define synonym mappings for search terms in a Search index.

    Prerequisites

    Procedure

    To define the synonym mappings for a Search index, you must:

    Create a Synonym Collection

    You can create a synonym collection like any other collection in Capella. Create synonym collections to divide your synonyms based on language or other sorting criteria.

    You must create your synonym collections in the same bucket and scope where you want to create your Search index.

    For more information about how to create a new collection, see Create a Collection.

    Create Synonym Documents

    You can create the following types of synonym documents for use with the Search Service:

    Create a Unidirectional Synonym Document

    Unidirectional synonym documents define a one-way synonym relationship.

    A unidirectional synonym document contains an input array and a synonyms array. Any search for a term in input can return any term in synonyms.

    For example, a unidirectional synonym document for synonyms of the terms happy, joyful, and cheerful can be defined as:

    {
        "input": [
          "happy",
          "joyful",
          "cheerful"
        ],
        "synonyms": [
          "content",
          "delighted",
          "elated",
          "glad",
          "pleased"
        ]
    }

    A search for happy could return results for content, delighted, elated, glad, or pleased. A search for cheerful would not return results for happy.

    You can only include a single input and synonyms array per unidirectional synonym document.

    To insert a new document into your cluster with a command line tool or SDK, see Create Documents.

    To import multiple documents into your cluster at one time with the Couchbase Capella UI, command line tools, or an SDK, see Import and Export Data.

    Create a Bidirectional Synonym Document

    Bidirectional synonym documents define a two-way synonym relationship. All terms are contained in a single synonyms array. Any search for a term in the synonyms array can return any other term in the array.

    For example, a bidirectional synonym document for synonyms of the word happy could be defined as:

    {
      "synonyms": [
        "cheerful",
        "content",
        "delighted",
        "elated",
        "glad",
        "happy",
        "joyful",
        "pleased"
      ]
    }

    A search for cheerful, happy, or 1 of the other terms in the array could return results for any other term.

    You can only include a single synonyms array per bidirectional synonym document.

    To insert a new document into your cluster with a command line tool or SDK, see Create Documents.

    To import multiple documents into your cluster at one time with the Couchbase Capella UI, command line tools, or an SDK, see Import and Export Data.

    Next Steps

    To use your defined synonyms in a Search index, see Add a Synonym Source.