All Products
Search
Document Center

OpenSearch:Batch query

Last Updated:May 26, 2025

URL

/vector-service/batch-query

  • The preceding URL omits information such as request header parameters and encoding.

  • The preceding URL also omits the host endpoint that is used to connect to an 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

Signature mechanism

You can use the following method to calculate a signature (authorization).

Parameter

Type

Description

accessUserName

string

The username. To view a username, choose Instance Details > API Endpoint.

accessPassWord

string

The password. To modify a password, choose Instance Details > API Endpoint.

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==

If using an HTTP request, you must add the Basic prefix to the authorization header.

Example:

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

Request body

Parameter

Description

Default value

Type

Required

queries

The batch query list.

[]

List<Query>

Yes

timeout

The timeout period.

-1 (which indicatng no timeout).

Integer

No

Query:

Parameter

Description

Default value

Type

Required

tableName

The name of the table to query.

N/A

string

Yes

vector

The vector data to query.

N/A

list[float]

Yes

vectorCount

The number of vectors included in the vector field.

1

int

No

namespace

The namespace of the vector to query.

""

string

No

topK

The number of results to return.

100

int

No

indexName

The name of the index to query.

""

string

No

sparseData

The sparse vector to query.

No sparse vectors by default

SparseData

No

includeVector

Specifies whether to return the vector information in the document.

false

bool

No

outputFields

The list of fields to return.

[]

list[string]

No

order

The sorting order. Valid values:

  • ASC

  • DESC

ASC

string

No

searchParams

The query parameter.

""

string

No

filter

The filter expression.

""

string

No

scoreThreshold

The score filter. When using Euclidean distance, only results with scores less than the scoreThreshold value are returned. When using inner product distance, only results with scores greater than the scoreThreshold value are returned.

By default, the results are not filtered.

float

No

sort

The sort expression.

""

string

No

Response parameters

Parameter

Description

Type

result

The result list. The order of results for each query is consistent with the order in the query.

List[QueryResult]

totalTime

The query duration in milliseconds.

Integer

errorCode

The error code returned if the request failed.

Integer

errorMsg

The error message returned if the request failed.

String

  • QueryResult:

    Parameter

    Description

    Type

    queryId

    The ID of the query to which the result belongs.

    Integer

    totalCount

    The number of results.

    Integer

    data

    The list of result documents.

    List[Item]

  • Item:

    Parameter

    Description

    Type

    id

    The primary key value. The value is of the defined data type.

    FieldType

    score

    The score of the vector.

    Float

    fields

    The fields and the corresponding values.

    Map<String, FieldType>

    vector

    The vector value.

    List[Float]

    namespace

    The namespace of the vector. This parameter is returned if a namespace is configured for the vector.

    String

Examples

Sample request:

{
    "queries":
    [
        {
            "indexName": "vector",
            "outputFields":
            [
                "id",
                "name"
            ],
            "tableName": "test",
            "vector":
            [
                0.363397,
                0.843076,
                0.47759,
                0.48623
            ]
        },
        {
            "indexName": "vector",
            "outputFields":
            [
                "id",
                "title"
            ],
            "tableName": "test1",
            "vector":
            [
                0.822608,
                0.972663,
                0.014438,
                0.410083
            ]
        }
    ]
}

Sample response:

{
    "result":
    [
        {
            "queryId": 0,
            "totalCount": 1,
            "data":
            [
                {
                    "id": 1,
                    "score": 0.521898,
                    "__source__": 0,
                    "fields":
                    {
                        "name": "Test1"
                    }
                }
            ]
        },
        {
            "queryId": 1,
            "totalCount": 1,
            "data":
            [
                {
                    "id": 1,
                    "score": 1.200817,
                    "__source__": 1,
                    "fields":
                    {
                        "title": "Title1"
                    }
                }
            ]
        }
    ],
    "totalTime": 4.419
}