Top search demo

更新时间:
复制 MD 格式

Find package dependencies: https://www.npmjs.com/

Code dependencies

  • dependencies

@alicloud/credentials 
@alicloud/opensearch-util 
@alicloud/tea-typescript 
@alicloud/tea-util
  • devDependencies

typescript
ts-node

Top search example

import * as $Util from '@alicloud/tea-util';
import Client from "./Client";
import Config from "./Config";

// Create a Config instance.
let config  = new Config();

// Configure the endpoint, which is the unified request entry point. Obtain this information from the console.
config.endpoint = "opensearch-cn-hangzhou.aliyuncs.com";

// Configure the network request protocol. The default is 'HTTP'. Valid values are 'HTTPS' and 'HTTP'.
config.protocol = "HTTP";

// Configure the authentication type. The default is 'access_key'. Set this to 'sts' to use RAM-STS authentication.
// Valid values: sts or access_key
config.type = "access_key";

// If you use RAM-STS authentication, configure the security_token. Call the Alibaba Cloud AssumeRole operation to obtain the required STS authentication information.
config.securityToken = "";

// Configure runtime parameters. The unit for time-related parameters is ms.
let runtime = new $Util.RuntimeOptions({
  connectTimeout: 5000,
  readTimeout: 10000,
  autoretry: false,
  ignoreSSL: false,
  maxIdleConns: 50,
});

// Create an OpenSearch client instance.
let client = new Client(config);

// Specify the name or version of the destination app.
const appName = "<appName>";


// ---------------  Top search hint ---------------
let hot_algoQuery = {
    "sort_type": "default",
    "hit": 10,
    "user_id": "a7a0d37c824b659f36a5b9e3b819fcdd"
  };
try {
  let pathname = `/v3/openapi/apps/${appName}/actions/hot`;
  let  result=  client._request("GET", pathname, hot_algoQuery, null, null, runtime);
  result.then(function (result)  {
    console.log(result);
  });
}
catch (e) {
  console.log(e);
}
Note

For more information, see Top search hints.