OSS + API data source

Updated at:

This topic describes how to add a table that uses Object Storage Service (OSS) + API as the data source.

To add an OSS + API data source, perform the following two steps:

  1. Activate OSS

  2. Add the OSS + API data source


Step 1: Activate OSS

1. Activate OSS

The OSS service that you activate must belong to the same account and the same region as your purchased OpenSearch service.

On the OSS resource plan purchase page, set Commodity Type to OSS Resource Plan, select a Resource Plan Type (such as Standard - ZRS) based on your business needs, and select the corresponding Region (such as Chinese Mainland).

Important
  • The OSS service must belong to the same account and the same region as your purchased OpenSearch service. Otherwise, authentication fails.

  • 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.

2. Create a bucket

Before you upload files to OSS, you must create a bucket to store the files. For more information, see Create a bucket.

Path: OSS console → Buckets → Create Bucket

Note
  • OpenSearch Retrieval Engine Edition does not support OSS buckets that have no region attribute.

Go to the created bucket and add an OpenSearch tag.

Path: Bucket Settings → Bucket Tagging → Create Tag

Set both the key and the value of the tag to opensearch.

3. Configure the OSS file format

a. OSS file format

To ensure that the transferred files can be used as the data source for index building, make sure that:

  • The files are encoded in UTF-8.

  • The file data is converted to the HA3 format or the JSON format.

i. JSON format

For an example that contains multiple records, see the following example:

{"field_double": ["100.0", "221.123", "500.3333333"], "field_int32": ["100", "200", "300"], "title": "Huawei Mate 9 Kirin 960 chip Leica dual camera", "color": "red", "empty_int32": "", "price": "3599", "CMD": "add", "nid": "1", "gather_cn_str": "", "desc": ["str1", "str2", "str3"], "brand": "Huawei", "size": "5.9","__subdocs__":[{"sub_pk":"100","sub_field1":"200","sub_field2":["100","200","300"]},{"sub_pk":"200","sub_field1":"200","sub_field2":["100","200","300"]}]}
{"field_double": ["100.0", "221.123", "500.3333333", "100.0", "221.123", "500.3333333"], "field_int32": ["100", "200", "300", "100", "200", "300"], "title": "Huawei P10 Plus all-network mobile phone", "color": "blue", "empty_int32": "", "price": "4388", "CMD": "add", "nid": "2", "gather_cn_str": "colorblue", "desc": ["str1", "str2", "str3", "str1", "str2", "str3"], "brand": "Huawei", "size": "5.5","__subdocs__":[{"sub_pk":"100","sub_field1":"200","sub_field2":["100","200","300"]},{"sub_pk":"200","sub_field1":"200","sub_field2":["100","200","300"]}]}

Note:

  • All JSON fields are of the string type. When the engine builds indexes, it converts the fields to the types specified in the schema.

  • '\n' indicates a line feed. A single record cannot contain line feeds.

ii. HA3 format
  1. First, take a 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^_
  1. File delimiter definitions: 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 table describes the file delimiters.

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 feed)

C-q C-7

C-v C-7

"\x1E\n"

1E0A

Command delimiter

^^ (followed by a line feed)

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

  1. 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 consistent with the order of fields in the schema, and 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^_
^^
  1. Delete command format: The delete command deletes the 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, the field needs to appear only once.

CMD=delete^_
PK=12345321^_
^^CMD=delete^_
PK=12345321^_
^^

b. Upload files to the bucket

Return to the management page of the newly created bucket. In the left-side navigation pane, choose Object Management → Objects → Upload Object .

In the Files to Upload section, select the method for scanning files, select the content to upload, and then click Upload Object to upload the files.

In the Task List panel that appears on the right, confirm that the file status is Uploaded.

Step 2: Add the OSS + API data source

Purchase an instance: For more information, see Purchase an OpenSearch Retrieval Engine Edition instance.

1. Basic table information

On the Instances page, find your purchased OpenSearch Retrieval Engine Edition instance and click Manage in the Actions column.

In the left-side navigation pane, choose Table Management → Add Table .

After you specify the basic information about the table, click Next.

  • Table Name: The name can contain letters, digits, and underscores (_), and can be up to 25 characters in length.

  • Number of Data Shards: Enter a positive integer that does not exceed 256. Shards are used to improve the speed of full data building and the performance of individual queries. (For some existing instances, all index tables must still have the same number of shards, or at least one index table must have 1 shard while all other index tables have the same number of shards.)

  • Number of Resources for Data Updates: the number of resources used for data updates. By default, each index is provided with two free update resources, each with 4 cores and 8 GB of memory. Resources that exceed the free quota incur fees. For more information, see Billing of OpenSearch Retrieval Engine Edition on the international site.

2. Data synchronization

Set Full Data Source to "OSS + API" and configure the other parameters. After the data source passes the Data Source Verification check, click Next .

Configuration description:

  • OSS Path: the path used to access OSS files. The path must start with /, and cannot contain the ?, =, or & characters. Files cannot be stored in the root directory. You must place them in a folder and then specify the path.

  • OSS Bucket: the name of the OSS bucket.

On the Buckets page of the OSS console, click the name of the target bucket (for example, zhyq-sz) to go to the management page of the bucket.

  • Data Format: The transferred files must be in OSS + API data source or OSS + API data source. Otherwise, the file data cannot be transferred.

  • Data Source Verification: After the verification is passed, you can proceed to the next step.

3. Index schema

Configure the fields and indexes, and then click Next.

Example field configuration: id (INT64, primary key, attribute field, data compression: equal), fb_string (STRING, multi-value with a comma as the delimiter, data compression: uniq), name (TEXT, analysis method: Chinese - General Analysis), and code (STRING, attribute field, data compression: uniq, custom default value: <EMPTY_STRING>).

For example, add the index index_name (index type: TEXT, included field: name) and the index index_string (index type: STRING, included field: fb_string).

  • Configuration description:

    • Field settings:

      • Attribute field: You can specify whether to enable compression. By default, compression is disabled. Select file_compressor to enable compression.

      • Data compression: compresses field content by using methods such as deduplication. You can specify whether to compress field content. By default, compression is disabled. By default, uniq is selected for multi-value fields and STRING fields, and equal is selected for single-value numeric fields.

      • Setting notes:

        1. If you enable attribute compression, we recommend that you go to "Cluster Management - Node Status - Table Loading Policy" to edit the index loading method to reduce the impact on performance.

        2. Fields for which an analysis method is configured must be of the TEXT type.

        3. You can copy fields. The content of a new field created by copying (DUP field) remains consistent with the content of the original field (if inconsistent content is pushed, it is overwritten by the content of the original field). If you want the field content to be different, manually delete the copy from configuration in the advanced settings of the DUP field.

        4. If a field is missing from the data or a field is empty, the system automatically fills in a default value. By default, 0 is filled in for numeric fields and an empty string is filled in for STRING fields. Custom default values are supported.

    • Index settings: Configure indexes for the fields that need to be retrieved by using indexes.

4. Confirm creation

After you click Confirm Creation, the system automatically creates the configured table.