createIndex method
- String organizationId,
- IndexableCollection collectionType,
- Map<
String, dynamic> indexSpec, { - String? pipelineName,
CreateIndex starts a custom index build
_viam = await Viam.withApiKey(
dotenv.env['API_KEY_ID'] ?? '',
dotenv.env['API_KEY'] ?? ''
);
final dataClient = _viam.dataClient;
try {
// Create index
await this.createIndex(
"<YOUR-ORG-ID>",
IndexableCollection.INDEXABLE_COLLECTION_PIPELINE_SINK,
{
'keys': {'field1': 1}
}
);
print('Successfully created index');
} catch (e) {
print('Error creating index: $e');
}
For more information, see Data Client API.
Implementation
Future<void> createIndex(String organizationId, IndexableCollection collectionType, Map<String, dynamic> indexSpec,
{String? pipelineName}) async {
final request = CreateIndexRequest()
..organizationId = organizationId
..collectionType = collectionType
..indexSpec.add(BsonCodec.serialize(indexSpec).byteList);
if (pipelineName != null) {
request.pipelineName = pipelineName;
}
await _dataClient.createIndex(request);
}