Set a Document Filter

  • Capella Operational
  • how-to
    +
    Use a document filter with a type mapping to add an extra filter to the documents you want to include in a Search index.

    For more information about document filters and type mappings, see Search Index Features.

    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 started to create or already created an index in Advanced Mode Editing.

    • You have created at least one type mapping in your Search index. For more information, see Create a Search Index with the Capella UI.

    • You have logged in to the Couchbase Capella UI.

    Procedure

    To set a document filter for a Search index with the Capella UI:

    1. On the Operational Clusters page, select the operational cluster where you want to work with the Search Service.

    2. Go to Data Tools  Search.

    3. Do one of the following:

      1. To work with an existing Search index, click the name of the index where you want to create a document filter.

      2. To create a new Search index, click Create Search Index.

    4. Make sure to select Enable Advanced Options.

    5. Expand Global Index Settings.

    6. Do one of the following:

    Create a JSON Type Field Document Filter

    To only add documents to your Search index that contain a specific field with a specified string value:

    1. Under Choose Document Filter, click JSON Type Field

    2. In the JSON Type Field field, enter the name of the field in your documents that you want to use to filter documents in your Search index.

      For example, if your documents include a type field, you could enter type in the JSON Type Field field.

      You cannot use a field as a document filter if the field name contains a period (.).
    3. Under Type Mappings, next to the type mapping where you want to add the document filter, go to More Options (⋮)  Edit.

    4. In the Name field, add a period (.) to the end of the current type mapping name.

    5. After the period, add the exact string from the document field that you want to use as a filter.

      For example, if you wanted your Search index to only return documents that had a type value of hotel, you could enter hotel.

    6. Click Submit.

    7. Click Update Index.

    Create a Doc ID Up To Separator Document Filter

    To only add documents to your Search index that have IDs that match a specified prefix:

    1. Under Choose Document Filter, click Doc ID up to Separator.

    2. In the Doc ID up to Separator field, enter the separator character from the ID prefix in your document ID values.

      For example, if you know all of your document ID values are prefixed by a string and an underscore (_), enter _.

    3. Under Type Mappings, next to the type mapping where you want to add the document filter, go to More Options (⋮)  Edit.

    4. In the Name field, add a period (.) to the end of the current type mapping name.

    5. After the period, add the exact prefix from the document’s ID value that you want to use as a filter.

      For example, if you wanted your Search index to only return documents that have an prefix of landmark_, you could enter landmark.

    6. Click Submit.

    7. Click Update Index.

    Create a Doc ID with Regex Document Filter

    To only add documents to your Search index that have IDs that match a specified RE2 regular expression:

    1. Under Choose Document Filter, click Doc ID with Regex.

    2. In the Doc ID with Regex field, enter the regular expression that you want to use to filter documents in your Search index.

      For example, if you wanted documents with ID values that contained _40, you could enter _[3-5]0 as your regular expression.

    3. Under Type Mappings, next to the type mapping where you want to add the document filter, go to More Options (⋮)  Edit.

    4. In the Name field, add a period (.) to the end of the current type mapping name.

    5. After the period, add a match for the regular expression from the document’s ID value that you want to use as a filter.

      For example, if you wanted your Search index to only return documents with ID values that contained _40, you could enter _40.

    6. Click Submit.

    7. Click Update Index.

    Next Steps

    After you set the document filter for your Search index, you can continue to customize your Search index:

    To run a search and test the contents of your Search index, see Run A Simple Search with the Capella UI.