This topic provides code examples for using the Java SDK client to perform real-time data synchronization with an OpenSearch Vector Search Edition instance. The supported operations are add and delete.
Upload a document
package com.aliyun.ha3engine;
import com.aliyun.ha3engine.Client;
import com.aliyun.ha3engine.models.*;
import com.aliyun.tea.TeaException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* @author alibaba
*/
public class PushDoc {
public static void main(String[] args) throws Exception {
Config config = new Config();
// The API endpoint. You can find this on the API Endpoint tab of the Instance Details page.
config.setEndpoint("<instance_services_domain>");
// The instance name. You can find this in the upper-left corner of the Instance Details page. Example: ha-cn-i7*****605.
config.setInstanceId("<instance_id>");
// The username. You can find this on the API Endpoint tab of the Instance Details page.
config.setAccessUserName("<user_name>");
// The password. You can change the password on the API Endpoint tab of the Instance Details page.
config.setAccessPassWord("<user_password>");
Client client = new Client(config);
// The name of the table to push documents to, formatted as "Sample structure
[
{
"cmd":"add",
"fields":{
"id":"1",
"title":"This is the title",
"body":"This is the body",
"tags":[
1,
2,
3
]
}
}
]Delete a document
package com.aliyun.ha3engine;
import com.aliyun.ha3engine.Client;
import com.aliyun.ha3engine.models.*;
import com.aliyun.tea.TeaException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* @author alibaba
*/
public class PushDoc {
public static void main(String[] args) throws Exception {
Config config = new Config();
// The API endpoint. You can find this on the API Endpoint tab of the Instance Details page.
config.setEndpoint("<instance_services_domain>");
// The instance name. You can find this in the upper-left corner of the Instance Details page. Example: ha-cn-i7*****605.
config.setInstanceId("<instance_id>");
// The username. You can find this on the API Endpoint tab of the Instance Details page.
config.setAccessUserName("<user_name>");
// The password. You can change the password on the API Endpoint tab of the Instance Details page.
config.setAccessPassWord("<user_password>");
Client client = new Client(config);
// The name of the table to push documents to, formatted as "Sample structure
[
{
"cmd":"delete",
"fields":{
"id":"3"
}
}
]该文章对您有帮助吗?