restful api文檔搜索Demo
更新時間:
通過SDK 調(diào)用問天搜索引擎進行數(shù)據(jù)檢索。
通用代碼示例
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 SearchDoc {
public static void main(String[] args) throws Exception {
Config config = new Config();
// 用戶名,可在實例詳情頁>網(wǎng)絡(luò)信息 查看
config.setAccessUserName("<userName>");
// 密碼,可在實例詳情頁>網(wǎng)絡(luò)信息 修改
config.setAccessPassWord("<password>");
// 實例名稱,可在實例詳情頁左上角查看,例:ha-cn-i7*****605
config.setInstanceId("<instanceID>");
//私網(wǎng)域名調(diào)用請?zhí)顚慹ndpoint,如需私網(wǎng)域名調(diào)用,請打開如下注釋
//config.setEndpoint("ha-cn-******.ha.aliyuncs.com");
//公網(wǎng)域名調(diào)用請?zhí)顚慹ndpoint,如需公網(wǎng)域名調(diào)用,請打開如下注釋
//config.setEndpoint("ha-cn-******.public.ha.aliyuncs.com");
//公網(wǎng)ip調(diào)用填寫httpProxy,如需要公網(wǎng)IP調(diào)用,請打開如下注釋
//config.setHttpProxy("http://公網(wǎng)ip:端口");
Client client = new Client(config);
try {
/*
示例: 使用restful api方式查詢
*/
//body查詢參數(shù)自定義
JSONObject body = new JSONObject();
body.put("query", "index_id:1");
JSONObject configJson = new JSONObject();
configJson.put("format", "json");
body.put("config", configJson);
//索引表名
String indexName = "index_odps";
SearchRequestModel haQueryRequestModel = new SearchRequestModel();
haQueryRequestModel.setBody(body.toJSONString());
SearchResponseModel searchResponseModel = client.SearchRest(haQueryRequestModel, indexName);
System.out.println("result:" + searchResponseModel.getBody());
} catch (TeaException e) {
System.out.println(e.getMessage());
Map<String, Object> abc = e.getData();
System.out.println(com.aliyun.teautil.Common.toJSONString(abc));
}
}
}
文檔內(nèi)容是否對您有幫助?