All Products
Search
Document Center

OpenSearch:Primary key-based query

Last Updated:Feb 27, 2024

URL

/vector-service/fetch

  • The sample URL omits information such as the request headers and the encoding method.

  • The sample URL also omits the endpoint that is used to connect to an OpenSearch application.

  • For more information about the definitions, usage, and example values of all the request parameters that are concatenated in the preceding URL, see the "Request parameters" section of this topic.

Protocol

HTTP

Request method

POST

Supported format

JSON

Request signature

You can use the following method to calculate the request signature. The request signature is stored in the authorization header.

Parameter

Type

Description

accessUserName

string

The username. You can view the username on the API Endpoint tab of the Instance Details page.

accessPassWord

string

The password. You can modify the password on the API Endpoint tab of the Instance Details page.

import com.aliyun.darabonba.encode.Encoder;
import com.aliyun.darabonbastring.Client;

public class GenerateAuthorization {
 public static void main(String[] args) throws Exception {
 String accessUserName = "username";
 String accessPassWord = "password";
 String realmStr = "" + accessUserName + ":" + accessPassWord + "";
 String authorization = Encoder.base64EncodeToString(Client.toBytes(realmStr, "UTF-8"));
 System.out.println(authorization);
 }
}

Valid format for the value of the authorization header:

cm9vdDp******mdhbA==

You must add the Basic prefix when you specify the authorization header in an HTTP request.

Example:

authorization: Basic cm9vdDp******mdhbA==

Request parameters

Parameter

Description

Type

Required

tableName

The table name.

string

Yes

ids

The IDs.

list[string]

Yes

Example of querying data of the specified primary key field:

{
    "tableName": "gist",
    "ids": [
        "1",
        "2",
        "3"
    ]
}

Response parameters

Parameter

Description

Type

result

The returned results.

list[Doc]

totalCount

The number of results.

int

totalTime

The response time. Unit: milliseconds.

float

errorCode

The error code returned if the request failed.

int

errorMsg

The error message returned if the request failed.

string

  • Doc

Parameter

Description

Type

id

The primary key field.

The data type is specified when you create the table.

vector

The vector field.

list[float]

fields

The attribute field of a vector.

map<string, FieldType>

Example:

{
    "result": [
        {
            "id": "1",
            "vector": [
                0.1,
                0.2,
                0.3
            ],
            "fields": {
                "a": 11
            }
        }
    ],
    "totalCount": 1,
    "totalTime": 1.2
}