文档

restful api文档搜索Demo

通过SDK 调用问天搜索引擎进行数据检索。

通用代码示例

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();
        // 用户名,可在实例详情页>网络信息 查看
        config.setAccessUserName("<userName>");
        // 密码,可在实例详情页>网络信息 修改
        config.setAccessPassWord("<password>");
        //  实例名称,可在实例详情页左上角查看,例:ha-cn-i7*****605
        config.setInstanceId("<instanceID>");

        //私网域名调用请填写endpoint,如需私网域名调用,请打开如下注释
        //config.setEndpoint("ha-cn-******.ha.aliyuncs.com");
        //公网域名调用请填写endpoint,如需公网域名调用,请打开如下注释
        //config.setEndpoint("ha-cn-******.public.ha.aliyuncs.com");
        //公网ip调用填写httpProxy,如需要公网IP调用,请打开如下注释
        //config.setHttpProxy("http://公网ip:端口");

        Client client = new Client(config);


        try {
            /*
            示例: 使用restful api方式查询
             */
            //body查询参数自定义
            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));
        }
    }
}

  • 本页导读 (0)
文档反馈