Skip to main content

search_services

Creates, updates, deletes, gets or lists a search_services resource.

Overview

Namesearch_services
TypeResource
Idsnowflake.cortex_search_service.search_services

Fields

The following fields are returned by SELECT queries:

A Snowflake cortex search service object.

NameDatatypeDescription
namestringSpecifies the name for the cortex search service, must be unique for the schema in which the cortex search service is created
database_namestringDatabase in which the cortex search service is stored
schema_namestringSchema in which the cortex search service is stored
attribute_columnsarraySpecifies the attribute columns, which can be referenced in filters in search queries to the cortex search service.
columnsarraySpecifies all columns included in the cortex search service and that can be returned in search queries.
commentstringSpecifies a comment for the cortex search service
created_onstring (date-time)Date and time when the cortex search service was created.
data_timestampstring (date-time)Date and time as of which data existent in base tables is now serving.
definitionstringSpecifies the definition (source query) used to create the cortex search service (example: SELECT col1, col2 FROM foo)
indexing_errorstringError encountered during the latest indexing pipeline of the cortex search service, if any.
indexing_statestring
search_columnstringSpecifies the name of the search column for the cortex search service.
serving_data_bytesinteger (int64)Size of the serving index, in bytes.
serving_statestring
source_data_num_rowsinteger (int64)Number of rows in the materialized source data feeding into the cortex search service.
target_lagobjectSpecifies the schedule for periodically refreshing the dynamic table.
warehousestringSpecifies the name of the warehouse that provides the compute resources for refreshing the cortex search service (example: test_wh)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
list_cortex_search_servicesselectdatabase_name, schema_name, endpointlike, fromName, showLimitLists the cortex search services under the database and schema.
fetch_cortex_search_serviceselectdatabase_name, schema_name, name, endpointFetch a Cortex Search Service.
create_cortex_search_serviceinsertdatabase_name, schema_name, endpointcreateModeCreate a cortex search service, with standard create modifiers as query parameters. See the Cortex Search Service component definition for what is required to be provided in the request body.
delete_cortex_search_servicedeletedatabase_name, schema_name, name, endpointifExistsDelete a cortex search service with the given name. If ifExists is used, the operation will succeed even if the object does not exist. Otherwise, there will be a failure if the drop is unsuccessful.
query_cortex_search_serviceexecdatabase_name, schema_name, service_name, endpointQuery a Cortex Search Service to get search results.
suspend_cortex_search_serviceexecdatabase_name, schema_name, name, endpointifExists, targetSuspends one or both of the indexing or serving targets of a cortex search service.
resume_cortex_search_serviceexecdatabase_name, schema_name, name, endpointifExists, targetResume the cortex search service

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
database_namestringIdentifier (i.e. name) for the database to which the resource belongs. You can use the /api/v2/databases GET request to get a list of available databases.
endpointstringOrganization and Account Name (default: orgid-acctid)
namestringIdentifier (i.e. name) for the resource.
schema_namestringIdentifier (i.e. name) for the schema to which the resource belongs. You can use the /api/v2/databases/{database}/schemas GET request to get a list of available schemas for the specified database.
service_namestringThe name of the Cortex Search Service.
createModestringQuery parameter allowing support for different modes of resource creation. Possible values include: - errorIfExists: Throws an error if you try to create a resource that already exists. - orReplace: Automatically replaces the existing resource with the current one. - ifNotExists: Creates a new resource when an alter is requested for a non-existent resource.
fromNamestringQuery parameter to enable fetching rows only following the first row whose object name matches the specified string. Case-sensitive and does not have to be the full name.
ifExistsbooleanQuery parameter that specifies how to handle the request for a resource that does not exist: - true: The endpoint does not throw an error if the resource does not exist. It returns a 200 success response, but does not take any action on the resource. - false: The endpoint throws an error if the resource doesn't exist.
likestringQuery parameter to filter the command output by resource name. Uses case-insensitive pattern matching, with support for SQL wildcard characters.
showLimitintegerQuery parameter to limit the maximum number of rows returned by a command.
targetstringQuery parameter that identifies the target to which suspension or resumption of the cortex search service should be applied.

SELECT examples

Lists the cortex search services under the database and schema.

SELECT
name,
database_name,
schema_name,
attribute_columns,
columns,
comment,
created_on,
data_timestamp,
definition,
indexing_error,
indexing_state,
search_column,
serving_data_bytes,
serving_state,
source_data_num_rows,
target_lag,
warehouse
FROM snowflake.cortex_search_service.search_services
WHERE database_name = '{{ database_name }}' -- required
AND schema_name = '{{ schema_name }}' -- required
AND endpoint = '{{ endpoint }}' -- required
AND like = '{{ like }}'
AND fromName = '{{ fromName }}'
AND showLimit = '{{ showLimit }}';

INSERT examples

Create a cortex search service, with standard create modifiers as query parameters. See the Cortex Search Service component definition for what is required to be provided in the request body.

INSERT INTO snowflake.cortex_search_service.search_services (
data__name,
data__search_column,
data__columns,
data__attribute_columns,
data__target_lag,
data__warehouse,
data__definition,
data__comment,
data__indexing_state,
data__serving_state,
database_name,
schema_name,
endpoint,
createMode
)
SELECT
'{{ name }}' --required,
'{{ search_column }}' --required,
'{{ columns }}',
'{{ attribute_columns }}',
'{{ target_lag }}' --required,
'{{ warehouse }}' --required,
'{{ definition }}' --required,
'{{ comment }}',
'{{ indexing_state }}',
'{{ serving_state }}',
'{{ database_name }}',
'{{ schema_name }}',
'{{ endpoint }}',
'{{ createMode }}'
;

DELETE examples

Delete a cortex search service with the given name. If ifExists is used, the operation will succeed even if the object does not exist. Otherwise, there will be a failure if the drop is unsuccessful.

DELETE FROM snowflake.cortex_search_service.search_services
WHERE database_name = '{{ database_name }}' --required
AND schema_name = '{{ schema_name }}' --required
AND name = '{{ name }}' --required
AND endpoint = '{{ endpoint }}' --required
AND ifExists = '{{ ifExists }}';

Lifecycle Methods

Query a Cortex Search Service to get search results.

EXEC snowflake.cortex_search_service.search_services.query_cortex_search_service 
@database_name='{{ database_name }}' --required,
@schema_name='{{ schema_name }}' --required,
@service_name='{{ service_name }}' --required,
@endpoint='{{ endpoint }}' --required
@@json=
'{
"query": "{{ query }}",
"multi_index_query": "{{ multi_index_query }}",
"columns": "{{ columns }}",
"filter": "{{ filter }}",
"limit": {{ limit }},
"scoring_config": "{{ scoring_config }}",
"experimental": "{{ experimental }}"
}';