batch operation
Image Search supports batch operations to import images from Object Storage Service (OSS) or delete images that are already in the search index. The batch operation feature is stable, fast, and easy to use, making it ideal for managing large volumes of offline image data. This topic describes how to add and delete images in bulk.
For more product details or technical support, click Online Consulting or contact us through our DingTalk group: 35035130.
Procedure
Activate OSS
If you have not activated the Object Storage Service (OSS), see Activate OSS. After you activate the service, you must create a bucket. For more information, see Create a bucket in the console.
OSS is billed separately. For more information, see billing overview.
Ensure that your OSS service and bucket are in the same region as your Image Search instance.
Import images into OSS
To import images, see Upload files.
You can use a custom storage path for your images. You only need to specify the image path when you create a batch task.
Create an increment.meta file
In the OSS path where your images are stored, create an increment.meta file. This file stores information related to the batch task.
The images referenced in the increment.meta file must be in the same bucket as the increment.meta file. Otherwise, the batch operation fails.
The filename increment.meta is required and cannot be changed. Image Search uses this specific name to read batch content.
Image Search supports batch operations on images in different paths within the same bucket. For example, assume the bucket is named
imagesearch, the increment.meta file is in the root directory of this bucket, the path isgirlCloth, and the image name isgirl_cloth8.jpg. In the meta file,PicNamemust be set to"PicName":"girlCloth/girl_cloth8.jpg". Note: Do not add a forward slash (/) beforegirlClothor aftergirl_cloth8.jpg. This logic applies to multi-level directories as well.You must include the file extension in the image names in OSS. For example, for an image named
girl_cloth10.jpg, you must specify"PicName":"girl_cloth10.jpg", not"PicName":"girl_cloth10". Otherwise, the processing fails.Each line in the
increment.metafile must represent a single image operation. Do not place multiple operations on the same line.
The following example shows a sample file in JSON format:
{"OperationType": "ADD","ProductId": "1000","PicName": "girl_cloth1.jpg","CategoryId": 0,"IntAttr": 0,"StrAttr": "value1","CustomContent": "k1:v1,k2:v2,k3:v3","Region": "20,40,60,80"}
{"OperationType": "ADD","ProductId": "1000","PicName": "girl_cloth2.jpg","CategoryId": 0,"IntAttr": 0,"StrAttr": "value2","CustomContent": "k1:v1,k2:v2,k3:v3","Region": "20,40,60,80"}
{"OperationType": "ADD","ProductId": "1001","PicName": "girl_cloth3.jpg","CategoryId": 1,"CustomContent": "k1:v1,k2:v2,k3:v3"}
{"OperationType": "ADD","ProductId": "1002","PicName": "girl_cloth4.jpg","CategoryId": 0,"CustomContent": "k1:v1,k2:v2,k3:v3","Crop": false}
{"OperationType": "ADD","ProductId": "1003","PicName": "girl_cloth7.jpg","CustomContent": "https://www.aliyun.com/imagesearch/girl_cloth7.jpg"}
{"OperationType": "ADD","ProductId": "1003","PicName": "girl_cloth6.jpg","CustomContent": "k1:v1,k2:v2,k3:v3"}
{"OperationType": "ADD","ProductId": "1006","PicName": "girlCloth/girl_cloth10.jpg","CustomContent": "k1:v1,k2:v2,k3:v3"}
{"OperationType": "DELETE","ProductId": "1004","PicName": "fengyi.jpg"}
{"OperationType": "DELETE","ProductId": "1005"}The following example shows a sample file in CSV format:
The following table describes the fields.
Parameter | Type | Required | Description |
OperationType | String | Yes | The operation type.
|
ProductId | String | Yes | A unique identifier for the image. It can be up to 256 characters long. |
PicName | String | Yes | The name of the image in the OSS bucket. It can be up to 256 characters long. Important
|
CategoryId | Integer | No | For more information, see Category reference.
|
CustomContent | String | Yes | User-defined content. It can be up to 4,096 characters long. Note
The search results include this value. You can use this field to store an image URL or other additional information to link the image to your business data. |
IntAttr | Integer | No | An integer attribute used for conditional filtering. Note
Use integer attributes in a filter condition to filter search results. The |
StrAttr | String | No | A string attribute up to 128 characters long, used for conditional filtering. Note
|
Crop | Boolean | No | Specifies whether to enable subject identification. The default value is true.
Note For Fabric Image Search and Copyrighted Image Search, this parameter is ignored. The search is always based on the entire image. |
Region | String | No | The subject area of the image. The format is Note
|
Image Search authorization
Image Search performs batch operations by using OSS. You must complete a one-click authorization the first time you use this feature. If you have already granted authorization, you can skip this step.
Log in to the Image Search console.
Select the target service type and instance.
Click the Batch Operation tab.

Click Create Batch Task, and in the dialog box that appears, click Confirm Authorization.
On the Cloud Resource Access Authorization page, click Confirm Authorization.
Create a batch task
Log in to the Image Search console.
Select the target service type and instance.
Click the Batch Operation tab.

Click Create Batch Task.

Set the parameters for the batch task.
Region
The region where the instance resides.
Bucket name
The name of your OSS bucket.
ImportantEnsure that the OSS service and the created bucket are in the same region as your Image Search instance.
Data path
The storage path for the images to be uploaded and the increment.meta file.

Meta file
Self-written (recommended): A file that lists the images to be processed. The file must be named increment.meta. The system can check if the file exists. For more information, see Create an increment.meta file.
Automatic generation: This option automatically scans the specified data directory for all eligible image files based on the entered bucket name and data path. Use this option with caution. After the file is generated, you must download the meta file from the task list and upload it to the correct OSS path to start the batch task.
NoteThe generated file contains only the required fields: OperationType (set to ADD), ProductId, and PicName. The values for PicName and ProductId are the same.
If you need to add other fields, download the generated file from the task list and modify it. For more information, see Create an increment.meta file.
Completion callback
Enter the callback URL. It must start with HTTP or HTTPS.
{ "finishTime": "2021-05-19 17:50:00", "instanceId": "imagesearch-cn-xxxx", "instanceName": "instanceName", "message": "success", "processResultUrl": "https://image-search-task-info.oss-cn-shanghai.aliyuncs.com/yyyyyyyyyy", "status": "NORMAL", "taskId": 111 }Field
Description
finishTime
The time the task completed, accurate to the second.
instanceName
The name of the Image Search instance.
instanceId
The ID of the Image Search instance.
status
The task execution result. NORMAL indicates success. FAIL indicates failure.
taskId
The task ID.
message
A description of the result.
successindicates that the task is successful.processResultUrl
The URL to download the error results.
Cancel a batch task
To cancel a task that is in the Processing state, click Cancel.

Read the content in the pop-up window and click OK to stop the batch task.

After you cancel the batch task, any processed data is retained, and the task status changes to Stop. Click download results to view the execution details.

Next steps
On the instance details page, you can view all batch tasks. For tasks in the Processing state, the task progress is displayed. After a batch task succeeds, you can view its corresponding message:
You can search for an instance by Bucket Name or Data Path.
If you receive the prompt Some photos failed to process and have been separated for you, it means that some images in the incremental task failed to process. Click Download Results to download the corresponding file and view the reasons for the failure.



