Object Storage Service (OSS)
Activate OSS

Add an OSS data source
-
Log on to the OpenSearch console. In the upper-left corner, switch to OpenSearch Retrieval Engine Edition. On the Instance Management page, find the instance in the list and click Manage in the Actions column.
-
Configure the data source.
In the left-side navigation pane, choose Configuration Center > Data Source. Click Add Data Source, select Object Storage Service (OSS), enter the Data Source Name, OSS Path, and Bucket, and then click Verify.
Parameters:
-
Data Source Name: a custom name for the data source. The name must start with a letter and can contain letters, digits, and underscores.
-
OSS Path: the path used to access the OSS files.
-
Bucket: the name of the OSS bucket.
-
The directory name must contain opensearch. Otherwise, data cannot be read. The directory name cannot contain special characters such as = & ?
-
Source of the OSS path: Click the name of the bucket that you created, create a directory, and then select the path of the created directory. In this example, the path is /opensearch_index_data/.
-
Bucket: the name of the OSS bucket. (Source: use the name of a bucket that you created in the activated OSS service.)
-
Add an index table:
-
After the OSS data source is created, add an index table on the Configuration Center > Index Schema page.
-
Configure the index table. You can customize the Index Table Name. For the data source, select the OSS data source that you configured:
-
In the field settings, add two fields: pk, with the field type STRING, set as the primary key, and the analysis method uniq; and embeddings, with the field type FLOAT, Multi-value selected, the delimiter ^], and the analysis method uniq. In the index settings, add two indexes: pk, with the index type PRIMARYKEY64 and the field pk; and vector, with the index type CUSTOMIZED and the fields pk,embeddings.
In this example, two fields are configured: pk and embeddings. For sample data, see oss_test.txt.
CMD=add
pk=999000
embeddings=0.00.0039257140.0098142860.0039257140.00
pk=999000
embeddings=0.00.0039257140
For the data format of the HA schema, see the HA file format section below.
-
Rebuild the index: Trigger an index rebuild on the O&M Center > O&M Management > Index Rebuild page:
In the index rebuild panel, select the Data Source Name (the configured OSS data source), confirm the Data Source Type and Associated Index Table, set the Timestamp, and then click OK. After the index is rebuilt, a full index version is generated. The version takes effect only after you switch it online.
After the index rebuild is complete, you can perform query tests.
HA file format
The file is the data source used to build the index (note: the file must be UTF-8 encoded) and has a fixed format. The following section describes the standard input format.
-
First, look at the content of a complete data file named standard_sample.data:
CMD=add^_
PK=12345321^_
url=http://www.aliyun.com/index.html^_
title=Alibaba Cloud Computing Co., Ltd.^_
body=xxxxxx xxx^_
time=3123423421^_
multi_value_field=1234^]324^]342^_
bidwords=mp3^\price=35.8^Ptime=13867236221^]mp4^\price=32.8^Ptime=13867236221^_
^^
CMD=delete^_
PK=12345321^_CMD=add^_
PK=12345321^_
url=http://www.aliyun.com/index.html^_
title=Alibaba Cloud Computing Co., Ltd.^_
body=xxxxxx xxx^_
time=3123423421^_
multi_value_field=1234^]324^]342^_
bidwords=mp3^\price=35.8^Ptime=13867236221^]mp4^\price=32.8^Ptime=13867236221^_
^^
CMD=delete^_
PK=12345321^_
The preceding data file contains two commands: add and delete. Each command consists of multiple lines, and each line is a key-value pair. Commands are separated by '^^\n', key-value pairs are separated by '^_\n', and multiple values are separated by '^]'. The following sections provide details.
-
File delimiter definitions
|
C++ encoding |
ASCII Hexadecimal |
Description |
Display form (in emacs/vi) |
Input method in emacs |
Input method in vi |
|
"\x1F\n" |
1F0A |
Key-value delimiter |
^_ (followed by a line break) |
C-q C-7 |
C-v C-7 |
|
"\x1E\n" |
1E0A |
Command delimiter |
^^ (followed by a line break) |
C-q C-6 |
C-v C-6 |
|
"\x1D" |
1D |
Multi-value delimiter |
^] |
C-q C-5 |
C-v C-5 |
|
"\x1C" |
1C |
Section weight identifier |
^\ |
C-q C-4 |
C-v C-4 |
|
"\x1D" |
1D |
Section delimiter |
^] |
C-q C-5 |
C-v C-5 |
|
"\x03" |
03 |
Sub-doc field delimiter |
^C |
C-q C-c |
C-v C-c |
-
Command format definitions
-
Add command format
The add command adds new content to the index.
The first line of an add command must be CMD=add, followed by the fields of the document. The field order can be the same as the order of fields in the schema. All fields that appear must be specified in fields.
-
CMD=add^_
PK=12345321^_
url=http://www.aliyun.com/index.html^_
title=Alibaba Cloud Computing Co., Ltd.^_
body=xxxxxx xxx^_
time=3123423421^_
multi_value_field=1234^]324^]342^_
bidwords=mp3^\price=35.8^Ptime=13867236221^]mp4^\price=32.8^Ptime=13867236221^_
^^CMD=add^_
PK=12345321^_
url=http://www.aliyun.com/index.html^_
title=Alibaba Cloud Computing Co., Ltd.^_
body=xxxxxx xxx^_
time=3123423421^_
multi_value_field=1234^]324^]342^_
bidwords=mp3^\price=35.8^Ptime=13867236221^]mp4^\price=32.8^Ptime=13867236221^_
^^
-
Delete command format
The delete command deletes specified content from the index.
The first "line" of a delete command must be CMD=delete. The subsequent "lines" are the field defined as the primary key in the index schema and the field used for
partition hashing. If the two fields are the same, only one of them needs to appear.
CMD=delete^_
PK=12345321^_
^^CMD=delete^_
PK=12345321^_
^^
Delete an OSS data source
On the Data Source Configuration page, find the data source that you want to delete and click Delete.
Note:
-
A deleted data source cannot be restored. Proceed with caution.
The confirmation dialog box that appears indicates that the index tables produced by the current data source will also be deleted. Click Confirm to complete the deletion.
-
If index tables have been configured for the OSS data source, you must delete the index tables before you can delete the OSS data source.
Usage notes
-
The activated OSS service must be in the same region as the purchased OpenSearch service.
-
OpenSearch Retrieval Engine Edition does not support OSS buckets that have no region attribute.
-
When you add an OSS data source, a service-linked role named AliyunServiceRoleForSearchEngine is automatically created (if the role already exists, it is not created again). OpenSearch uses this role to access your resources in other cloud services to implement the corresponding features.