> ## Documentation Index
> Fetch the complete documentation index at: https://doc.lucidworks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Couchbase V1

> The Couchbase V1 connector uses the Cross-Datacenter Replication (XDCR) feature of Couchbase to retrieve data stored in Couchbase continuously in real-time.

export const schema = {
  "category": "Other",
  "categoryPriority": 1,
  "description": "Couchbase server. Uses Cross-Datacenter Replication (XCDR) to index Couchbase documents in real time. It never ends unless you stop the datasource.",
  "properties": {
    "category": {
      "default": "Database",
      "hints": ["hidden", "readonly"],
      "title": "Category",
      "type": "string"
    },
    "connector": {
      "description": "Connector Type.",
      "hints": ["hidden"],
      "minLength": 1,
      "title": "Connector Type",
      "type": "string"
    },
    "description": {
      "description": "Optional description for this datasource.",
      "title": "Description",
      "type": "string"
    },
    "id": {
      "description": "Unique name for this datasource.",
      "minLength": 1,
      "pattern": "^[a-zA-Z0-9_-]+$",
      "title": "Datasource ID",
      "type": "string"
    },
    "pipeline": {
      "description": "Name of an existing index pipeline for processing documents.",
      "minLength": 1,
      "title": "Pipeline ID",
      "type": "string"
    },
    "properties": {
      "description": "Datasource configuration properties",
      "properties": {
        "client_host": {
          "default": "127.0.0.1",
          "description": "Host where Couchbase replica is running, which must be reachable from Couchbase server.",
          "minLength": 1,
          "title": "Couchbase client host",
          "type": "string"
        },
        "client_port": {
          "default": 9876,
          "description": "Port number where Couchbase client will be started.",
          "title": "Couchbase client port",
          "type": "integer"
        },
        "cluster_name": {
          "description": "Connector's cluster name in Couchbase server.",
          "minLength": 1,
          "title": "Cluster name",
          "type": "string"
        },
        "collection": {
          "description": "Collection documents will be indexed to.",
          "hints": ["hidden"],
          "pattern": "^[a-zA-Z0-9_-]+$",
          "title": "Collection",
          "type": "string"
        },
        "commit_on_finish": {
          "default": true,
          "description": "Set to true for a request to be sent to Solr after the last batch has been fetched to commit the documents to the index.",
          "hints": ["advanced"],
          "title": "Solr commit on finish",
          "type": "boolean"
        },
        "db": {
          "description": "Type and properties for a ConnectorDB implementation to use with this datasource.",
          "hints": ["hidden"],
          "properties": {
            "aliases": {
              "default": false,
              "description": "Keep track of original URI-s that resolved to the current URI. This negatively impacts performance and size of DB.",
              "title": "Process Aliases?",
              "type": "boolean"
            },
            "inlinks": {
              "default": false,
              "description": "Keep track of incoming links. This negatively impacts performance and size of DB.",
              "title": "Process Inlinks?",
              "type": "boolean"
            },
            "inv_aliases": {
              "default": false,
              "description": "Keep track of target URI-s that the current URI resolves to. This negatively impacts performance and size of DB.",
              "title": "Process Inverted Aliases?",
              "type": "boolean"
            },
            "type": {
              "default": "com.lucidworks.connectors.db.impl.MapDbConnectorDb",
              "description": "Fully qualified class name of ConnectorDb implementation.",
              "minLength": 1,
              "title": "Implementation Class Name",
              "type": "string"
            }
          },
          "required": ["type"],
          "title": "Connector DB",
          "type": "object"
        },
        "initial_mapping": {
          "category": "Field Transformation",
          "categoryPriority": 6,
          "description": "Provides mapping of fields before documents are sent to an index pipeline.",
          "hints": ["advanced"],
          "properties": {
            "condition": {
              "description": "Define a conditional script that must result in true or false. This can be used to determine if the stage should process or not.",
              "hints": ["code", "javascript", "advanced"],
              "title": "Condition",
              "type": "string"
            },
            "label": {
              "description": "A unique label for this stage.",
              "hints": ["advanced"],
              "maxLength": 255,
              "title": "Label",
              "type": "string"
            },
            "mappings": {
              "description": "List of mapping rules",
              "hints": ["advanced"],
              "items": {
                "properties": {
                  "operation": {
                    "default": "copy",
                    "description": "The type of mapping to perform: move, copy, delete, add, set, or keep.",
                    "enum": ["copy", "move", "delete", "set", "add", "keep"],
                    "hints": ["advanced"],
                    "title": "Operation",
                    "type": "string"
                  },
                  "source": {
                    "description": "The name of the field to be mapped.",
                    "hints": ["advanced"],
                    "title": "Source Field",
                    "type": "string"
                  },
                  "target": {
                    "description": "The name of the field to be mapped to.",
                    "hints": ["advanced"],
                    "title": "Target Field",
                    "type": "string"
                  }
                },
                "required": ["source"],
                "type": "object"
              },
              "title": "Field Mappings",
              "type": "array"
            },
            "reservedFieldsMappingAllowed": {
              "default": false,
              "hints": ["advanced"],
              "title": "Allow System Fields Mapping?",
              "type": "boolean"
            },
            "skip": {
              "default": false,
              "description": "Set to true to skip this stage.",
              "hints": ["advanced"],
              "title": "Skip This Stage",
              "type": "boolean"
            },
            "unmapped": {
              "description": "If fields do not match any of the field mapping rules, these rules will apply.",
              "hints": ["advanced"],
              "properties": {
                "operation": {
                  "default": "copy",
                  "description": "The type of mapping to perform: move, copy, delete, add, set, or keep.",
                  "enum": ["copy", "move", "delete", "set", "add", "keep"],
                  "hints": ["advanced"],
                  "title": "Operation",
                  "type": "string"
                },
                "source": {
                  "description": "The name of the field to be mapped.",
                  "hints": ["advanced"],
                  "title": "Source Field",
                  "type": "string"
                },
                "target": {
                  "description": "The name of the field to be mapped to.",
                  "hints": ["advanced"],
                  "title": "Target Field",
                  "type": "string"
                }
              },
              "required": ["source"],
              "title": "Unmapped Fields",
              "type": "object"
            }
          },
          "title": "Initial field mapping",
          "type": "object",
          "unsafe": false
        },
        "max_docs": {
          "default": -1,
          "description": "The maximum number of documents to process before stopping. The default, '-1', means no maximum and this connector will continue processing content indefinitely.",
          "title": "Max documents",
          "type": "integer"
        },
        "num_vbuckets": {
          "description": "Number of VBuckets used by Couchbase. Values should be 64 if Couchbase server is installed on Mac OS or 1024 for other platforms. Note that the number of VBuckets must be consistent for both Couchbase server and Couchbase Connector. Connector will try to obtain correct value from Couchbase server and the value specified will be used in case of failure.",
          "enum": [64, 1024],
          "hints": ["advanced"],
          "title": "Number of Couchbase VBuckets",
          "type": "integer"
        },
        "password": {
          "description": "Couchbase server's valid password.",
          "hints": ["secret"],
          "title": "Password",
          "type": "string"
        },
        "server_host": {
          "default": "127.0.0.1",
          "description": "Host where Couchbase server is running.",
          "minLength": 1,
          "title": "Couchbase server host",
          "type": "string"
        },
        "server_port": {
          "default": 8091,
          "description": "Port number where Couchbase server is running.",
          "title": "Couchbase server port",
          "type": "integer"
        },
        "source_buckets": {
          "description": "Couchbase buckets to synchronize with.",
          "items": {
            "category": "Other",
            "categoryPriority": 1,
            "description": "Bucket in the Couchbase server containing documents for synchronization.",
            "properties": {
              "fieldmapping": {
                "description": "Field mappings for Couchbase document's fields.",
                "items": {
                  "category": "Other",
                  "categoryPriority": 1,
                  "description": "Mapping rule for Couchbase document field.",
                  "properties": {
                    "field_name": {
                      "description": "Name of the field in Couchbase document.",
                      "title": "Field name",
                      "type": "string"
                    },
                    "field_path": {
                      "description": "XPath-style path to a field in Couchbase JSON document, e.g. /exams/marks. More examples: https://lucidworks.com/blog/indexing-custom-json-data/.",
                      "minLength": 1,
                      "title": "Field path",
                      "type": "string"
                    }
                  },
                  "title": "Field mapping rule",
                  "type": "object",
                  "unsafe": false
                },
                "minItems": 1,
                "title": "Field mappings",
                "type": "array"
              },
              "name": {
                "description": "Name of the bucket in the Couchbase server.",
                "minLength": 1,
                "title": "Bucket name",
                "type": "string"
              },
              "splitpath": {
                "default": "/",
                "description": "XPath-style path to the Couchbase document's element that can be used to split it into more documents, e.g. /exams. More examples: https://lucidworks.com/blog/indexing-custom-json-data/.",
                "title": "Splitpath",
                "type": "string"
              }
            },
            "required": ["name"],
            "title": "Source bucket",
            "type": "object",
            "unsafe": false
          },
          "minItems": 1,
          "title": "Source buckets",
          "type": "array"
        },
        "username": {
          "description": "Couchbase server's valid username.",
          "title": "Username",
          "type": "string"
        },
        "verify_access": {
          "default": true,
          "description": "Set to true to require successful connection to the filesystem before saving this datasource.",
          "hints": ["advanced"],
          "title": "Validate access",
          "type": "boolean"
        }
      },
      "propertyGroups": [{
        "label": "Field Mapping",
        "properties": ["initial_mapping"]
      }],
      "required": ["username", "password", "cluster_name", "source_buckets"],
      "title": "Properties",
      "type": "object"
    },
    "type": {
      "description": "Datasource type supported by the selected connector type.",
      "hints": ["hidden"],
      "minLength": 1,
      "title": "Datasource Type",
      "type": "string"
    },
    "type_description": {
      "default": "Couchbase server. Uses Cross-Datacenter Replication (XCDR) to index Couchbase documents in real time. It never ends unless you stop the datasource.",
      "hints": ["hidden", "readonly"],
      "title": "Type Description",
      "type": "string"
    }
  },
  "required": ["id", "connector", "type", "pipeline", "properties"],
  "title": "Couchbase",
  "type": "object",
  "unsafe": false
};

export const SchemaParamFields = ({schema}) => {
  const sanitize = str => {
    if (typeof str !== "string") return str;
    return str.replace(/^"(.*)"$/s, "$1").replace(/\\/g, "").replace(/"/g, "'");
  };
  const formatDescription = str => {
    const s = sanitize(str);
    return (/[.!?]\)*$/).test(s) ? s : `${s}.`;
  };
  const {description, properties = {}, required: requiredProps = []} = schema;
  const visibleProps = useMemo(() => Object.entries(properties).filter(([, prop]) => !prop.hints?.includes("hidden")), [properties]);
  return <div>
      {description && <p>{formatDescription(description)}</p>}

      {visibleProps.map(([name, prop]) => {
    const isRequired = requiredProps.includes(name);
    const hasDefault = prop.default !== undefined;
    const rawDefault = prop.default;
    const isComplexDefault = hasDefault && (typeof rawDefault === "object" || typeof rawDefault === "string" && (rawDefault.length > 20 || rawDefault.includes('"')));
    const fieldProps = {
      key: name,
      body: prop.title || name,
      type: prop.type,
      ...prop.title && ({
        post: [<><span className="text-stone-400 dark:text-stone-500">API property: </span>{name}</>]
      }),
      ...isRequired && ({
        required: true
      }),
      ...!isComplexDefault && hasDefault ? {
        default: sanitize(String(rawDefault))
      } : {}
    };
    const isObject = prop.type === "object" && prop.properties;
    const isArrayOfObjects = prop.type === "array" && prop.items?.type === "object" && prop.items.properties;
    return <ParamField {...fieldProps}>
            {prop.description && <p>{formatDescription(prop.description)}</p>}

            {isComplexDefault && <div className="flex">
                <p>
                  <strong>Default:</strong>
                </p>
                <pre className="!my-0">
                  <code>
                    {JSON.stringify(rawDefault, null, 2)}
                  </code>
                </pre>
              </div>}

            {isArrayOfObjects && <div className="flex">
              <p>
                <strong>Object attributes:</strong>
              </p>
              <pre className="!my-0">
                <code>
                  {'{\n'}
                  {Object.entries(prop.items.properties).map(([iname, iprop]) => <>
                      {`  ${iname}`}
                      {prop.items?.required?.includes(iname) && <span style={{
      color: 'red'
    }}> required</span>}
                      {`: {\n    display name: ${sanitize(iprop.title || '')}\n    type: ${iprop.type}\n  }\n`}
                    </>)}
                  {'}'}
                </code>
              </pre>
              </div>}

            {isObject && <Expandable title="properties">
                <SchemaParamFields schema={{
      properties: prop.properties,
      required: prop.required
    }} />
              </Expandable>}
          </ParamField>;
  })}
    </div>;
};

export const LwTemplate = ({title = "Key questions to get you started", icon = "sparkles", cta = "Powered by Agent Studio", linkHref = "https://lucidworks.com/demo/?utm_source=docs&utm_medium=referral&utm_campaign=docs_cta_ai"}) => {
  const [isLoaded, setIsLoaded] = useState(false);
  useEffect(() => {
    const timer = setTimeout(() => {
      setIsLoaded(true);
    }, 500);
    return () => clearTimeout(timer);
  }, []);
  return <div className="lw-template-container">
      <Card title={title} icon={icon}>
        {isLoaded && <span dangerouslySetInnerHTML={{
    __html: `<lw-template id="a029c1a9-28be-427e-b0e1-5d918920246a"></lw-template
            >`
  }} />}
        <Link href={linkHref} className="agent-studio-link text-left text-gray-600 gap-2 dark:text-gray-400 text-sm font-medium flex flex-row items-center hover:text-primary dark:hover:text-primary-light group-hover:text-primary group-hover:dark:text-primary-light">Powered by Lucidworks Agent Studio</Link>
      </Card>
    </div>;
};

[localhost link]: http://localhost:3000/docs/fusion-connectors/connectors/v1/couchbase

[mintlify link]: https://doc.lucidworks.com/docs/fusion-connectors/connectors/v1/couchbase

[old doc.lw link]: https://doc.lucidworks.com/fusion-connectors/58

<Callout icon="plug" color="#A4C6F7" iconType="solid">
  **Compatible with Fusion version:** 4.0.0 through 4.2.6
</Callout>

<Note>
  Deprecation and removal notice

  This connector is deprecated as of Fusion 4.2 and is removed or expected to be removed as of Fusion 5.0. Due to a dependency issue, the Couchbase V1 connector does not work as expected in Fusion 4.2. Use the Couchbase V2 connector instead.

  For more information about deprecations and removals, including possible alternatives, see [Deprecations and Removals](/docs/fusion-connectors/deprecations-and-removals).
</Note>

This connector has been tested for compatibility with Couchbase Server 2.5.1 Enterprise Edition.

<LwTemplate />

## Learn more

<AccordionGroup>
  <Accordion title="Configure Field Mapping for Couchbase">
    The Couchbase V1 connector uses the Cross-Datacenter Replication (XDCR) feature of Couchbase to retrieve data stored in Couchbase continuously in real-time.

    The Couchbase connector has built-in field mapping which allows mapping Couchbase fields to fields in your schema. The mapping configuration defines a field from your schema and an XPath-style path to the field in the Couchbase JSON document.

    The field mapping can accept wildcards and double-wildcards to map fields automatically. Wildcards can be used, but only at the end of the path definition.

    * `field_name=""` and `field_path=/docs/*` - maps all the fields under docs to the same name as given in JSON.
    * `field_name=""` and `field_path=/docs/**` - maps all the fields under docs and their children fields to the same name as given in JSON.
    * `field_name=searchField` and `field_path=/docs/*` - maps all the fields under /docs to a single field named 'searchField'.
    * `field_name=searchField` and `field_path=/docs/**` - maps all the fields under /docs and their children fields to a single field named 'searchField'.

    If mapping is not defined, a default mapping will be assigned, in the format of the second example above, i.e., `field_name=""` and `field_path=/docs/**.`

    This example shows some simple field mapping, using a single document such as this:

    ```json theme={"dark"}
    {
      "first": "John",
      "last": "Doe",
      "grade": 8,
      "exams": [
            {
            "subject": "Maths",
            "test"   : "term1",
            "marks": 90 },
            {
             "subject": "Biology",
             "test"   : "term1",
             "marks": 86 }
            ]
    }
    ```

    When we configure the datasource, we can define our field mapping as follows:

    ```json theme={"dark"}
    "field_mapping": [
    {
        "field_name":"points_i",
        "field_path":"/exams/marks"
    },
    {
        "field_name":"",
        "field_path":"/**"
    }
    ]
    ```

    Two mappings are defined. The first will map the `/exams/marks` field from Couchbase to the `points_i` field in Solr. The second maps all top-level and child fields from Couchbase to either the same field name in Solr or to a dynamic field rule.

    After retrieving the document, it should look like this:

    ```json theme={"dark"}
    {
      "first_s": "John",
      "last_s": "Doe",
      "grade_i": 8,
      "exams": [
            {
            "subject_s": "Maths",
            "test_s"   : "term1",
            "points_i":90},
            {
             "subject_s": "Biology",
             "test_s"   : "term1",
             "points_i":86}
            ]
    }
    ```

    The `marks` field from the original document has been mapped to the `points_i` field; most of the other fields have been mapped to appropriate dynamic field rules.

    Note that the representation of the document above is after it has been retrieved from Couchbase, but before it has been processed by the index pipelines. Since the index pipelines contain several stage types that can further transform the document, such as the Apache Tika Parser stage and the Field Mapping stage, the document that ends up indexed to Solr may be different from the document representation above. Some small iterations of crawling are recommended to be sure the documents are indexed as required.
  </Accordion>

  <Accordion title="Split Couchbase Documents">
    The Couchbase V1 connector uses the Cross-Datacenter Replication (XDCR) feature of Couchbase to retrieve data stored in Couchbase continuously in real-time.

    Because Couchbase has a flexible data model, documents may have a nested JSON structure. It is possible to split nested documents with a `splitpath` property, which uses an XPath-style path to the element to split on. These paths do not accept wildcards.

    <Tip>
      These paths do not accept wildcards.
    </Tip>

    For example, if you have a document that looks like this:

    ```json theme={"dark"}
    {
      "first": "John",
      "last": "Doe",
      "grade": 8,
      "exams": [
            {
            "subject": "Maths",
            "test"   : "term1",
            "marks":90},
            {
             "subject": "Biology",
             "test"   : "term1",
             "marks":86}
            ]
    }
    ```

    If we want to split this document on the `exams` element and create two documents, each with a different subject, we would define `"splitpath":"/exams"` in our datasource definition.

    <Tip>
      When using the Fusion UI to configure the datasource, enter the path *without* quotes.
    </Tip>

    The output from retrieving the document should look like this:

    ```json theme={"dark"}
    {
      "first": "John",
      "last": "Doe",
      "grade": 8,
      "exams": [
            {
            "subject": "Maths",
            "test"   : "term1",
            "marks":90
            }
        ]
    },
    {
      "first": "John",
      "last": "Doe",
      "grade": 8,
      "exams": [
            {
             "subject": "Biology",
             "test"   : "term1",
             "marks":86
            }
            ]
    }
    ```
  </Accordion>

  <Accordion title="Tune a Couchbase Datasource">
    The Couchbase V1 connector uses the Cross-Datacenter Replication (XDCR) feature of Couchbase to retrieve data stored in Couchbase continuously in real-time.

    Because the Couchbase connector retrieves data continuously, two properties are available to control the frequency of commits to Solr, which makes the documents available for user queries. The properties define the maximum number of documents to queue for a commit (set to 50,000 by default) and the maximum amount of time to wait between commits (set to 120 seconds, or 2 minutes). Documents will be committed when one of those thresholds is reached first, meaning that if 2 minutes have passed and there are only 20,000 documents, a commit will occur. Similarly, if only 1 minute has passed and there are 50,000 documents in the queue, a commit will occur. These properties can be adjusted for your own requirements if needed.
  </Accordion>
</AccordionGroup>

## Configuration

<Tip>
  When entering configuration values in the UI, use *unescaped* characters, such as `\t` for the tab character. When entering configuration values in the API, use *escaped* characters, such as `\\t` for the tab character.
</Tip>

<SchemaParamFields schema={schema} />
