Set the Type Identifier for a Search Index
- how-to
 
Use a type identifier with a type mapping to add an extra filter to the documents you want to include in a Search index.
For example, if you added a filter to your type mapping that checked if the value of a field was true, only documents with the value true for that field would be included in your Search index under that type mapping.
Based on your settings, child fields or child mappings that you define for documents that pass the filter on this type mapping will be returned in search results.
You can filter based on the value of a field, or part of the value of your document IDs.
As of Couchbase Server version 8.0, you can filter documents with custom filters based on the value of:
You can add up to a maximum of 100 custom document filters on a single Search index.
For more information about type identifiers and type mappings, see Customize a Search Index with the Web Console.
Prerequisites
- 
You have the Search Service enabled on a node in your cluster. For more information about how to deploy a new node and Services on your cluster, see Manage Nodes and Clusters.
 - 
You have a bucket with scopes and collections in your cluster. For more information about how to create a bucket, see Create a Bucket.
 - 
You have created an index. For more information, see Create a Basic Search Index with the Web Console.
 - 
You have created at least one type mapping in your Search index. For more information, see Create a Type Mapping.
 - 
Your user account has the
Search Adminrole for the bucket where you want to edit an index. - 
You have logged in to the Couchbase Server Web Console.
 
Procedure
To set a type identifier for a Search index with the Couchbase Server Web Console:
- 
Go to Search.
 - 
Click the index where you want to set a type identifier.
 - 
Click Edit.
 - 
Expand Type Identifier.
 - 
Do one of the following:
- 
(Couchbase Server version 8.0 and later) Create a Custom Document Filter Type Identifier
 
 
| You cannot use custom document filters with another type of type identifier on your Search index. If you select an option other than Custom after you have defined custom document filters, you’ll lose any defined custom filters on your Search index. | 
Create a JSON Type Field Type Identifier
To only add documents to your Search index that contain a specific field with a specified string value:
- 
Select JSON type field.
 - 
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
typefield, you could entertypein the JSON Type Field field.You cannot use a field as a type identifier if the field name contains a period (.).  - 
Under Type Mappings, next to the type mapping where you want to add the type identifier, click Edit.
 - 
In the # field, add a period (.) to the end of the current type mapping name.
 - 
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 type mapping to only include documents that had a value of
hotelin thetypefield, you could enterscope.collection.hotelin the type mapping # field. - 
Click OK.
 - 
Click Update Index.
 
Create a Doc ID Up To Separator Type Identifier
To only add documents to your Search index that have IDs that match a specified prefix:
- 
Select Doc ID up to Separator.
 - 
In the Doc ID up to Separator field, enter the ID prefix, up to the separator character, that you want to use to filter documents in your Search index.
For example, if you know all of your document ID values are prefixed by a string and an underscore (_), enter
_. - 
Under Type Mappings, next to the type mapping where you want to add the type identifier, click Edit.
 - 
In the # field, add a period (.) to the end of the current type mapping name.
 - 
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 type mapping to only include documents that have an prefix of
landmark_in their ID values, you could enterscope.collection.landmarkin the type mapping # field. - 
Click OK.
 - 
Click Update Index.
 
Create a Doc ID with Regex Type Identifier
To only add documents to your Search index that have IDs that match a specified RE2 regular expression:
- 
Select Doc ID with Regex.
 - 
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 only documents with ID values that contained
_40, you could enter_[3-5]0as your regular expression. - 
Under Type Mappings, next to the type mapping where you want to add the type identifier, click Edit.
 - 
In the # field, add a period (.) to the end of the current type mapping name.
 - 
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 type mapping to only include documents with ID values that contained
_40, you could enterscope.collection._40in the type mapping # field. - 
Click OK.
 - 
Click Update Index.
 
Create a Custom Document Filter Type Identifier
Couchbase Server 8.0
To create a new custom document filter on a Search index with the Couchbase Server Web Console:
- 
Select Custom.
 - 
Click + Add Document Filter.
 - 
In the Type field, enter a name for your new document filter.
 - 
In the Filter code editor, enter a JSON object to define your document filter.
For more information about the properties for each document filter type, see:
- 
Do not add the name of your document filter to your filter definition when defining a custom document filter through the Server Web Console. Define the document filter as an unnamed object with the specific properties you need for your document filter type.  
 - 
Click Save.
 - 
Under Type Mappings, next to the type mapping where you want to add the type identifier, click Edit.
 - 
In the # field, add a period (.) to the end of the current type mapping name.
 - 
After the period, enter the name of the custom document filter that you want to use to filter documents on this type mapping.
For example, if you defined a custom document filter named
free_breakfast_true, enterscope.collection.free_breakfast_truein the type mapping # field. - 
Click OK.
 - 
Click Update Index.
 
Next Steps
After you set the type identifier 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 Web Console or Run a Simple Search with the REST API and curl/HTTP.