Multi-path search

Updated at:

The multi-path search API allows a single request to run up to N independent queries in parallel, then merge and rank their results. You can customize the retrieval quota and priority of each path and trace the source of the final results. This is suitable for complex searches that combine text, vectors, indexes, or query strategies.

Key concepts

  • Multi-path search: A single search request runs multiple independent queries in parallel. Each query is a path. Documents returned by all path paths are deduplicated, merged, and ranked to produce one result list.

  • Query group: If the priority (priority) values are equal, the path entries form a query group. Each path in the group shares retrieval quotas (quota). For example, a group contains paths A and B, each with a quota of 100. If A retrieves only 70 documents, the remaining 30 units of quota can be used by B, allowing B to retrieve up to 130 documents.

  • Derived vector search: When a text query matches a text embedding rule configured in query analysis in the console, the system automatically derives a new vector query. Its priority is the same as that of the parent text path, and quota defaults to 0, which means that it shares the parent text path quota (quota).

Request

POST

URL

/v3/openapi/apps/$app_name/multi-path-search
Note
  • $app_name: the application name. Advanced and Standard editions support multiple application versions, so specify the application name. Requests normally access the serving version; an offline application ID accesses the offline application search service.

  • The preceding URL omits request headers, encoding, and similar details.

  • The preceding URL omits the application host address.

Request parameters

The request body is a JSON object containing a queries array that defines each query path and other global request parameters.

Global request parameters

Parameter

Type

Required

Default value

Description

raw_query

String

No

""

The original user query, used for query analysis or logging.

start

Integer

No

0

The pagination start position. Results start from document start. Valid range: [0, 5000].

hit

Integer

No

10

The maximum number of documents to return in this request. Valid range: [1, 500].

format

String

No

fulljson

The result format.

fetch_fields

String

No

All fields

The document fields to return, separated by semicolons (;).

unified_rank_size

Integer

No

2000

The total number of documents for unified ranking. The system selects up to unified_rank_size documents from the paths by priority for final ranking. Valid range: [1, 10000].

unified_rank_type

String

No

none

The unified ranking type. Valid values:
• rrf: Uses Reciprocal Rank Fusion to merge and rank results from multiple paths.
• cava_script: Uses a custom Cava script for ranking.

Text relevance scoring is unavailable in Cava scripts for unified ranking. You can use models such as CTR for scoring.
• none: Skips unified ranking.

unified_rank_name

String

No

""

The ranking script name. Required when unified_rank_type is cava_script.

vector_search

Object

No

{}

Vector retrieval configuration,For parameter details, see Vector retrieval.

user_id

String

No

""

The unique identifier of the end user, used for UV statistics or model training.

trace

String

No

""

The search log level, used for troubleshooting.

rank_trace

String

No

""

The ranking log level, used for troubleshooting.

Objects in the queries array

Each JSON object in the queries array represents an independent query path.

Parameter

Type

Required

Default value

Description

path

String

Yes

-

The unique identifier of the current query path. It can be traced in ranking logs.

query

String

Yes

-

The query clause, which defines the retrieval conditions for this path. For syntax, see Index retrieval - query clause.

priority

Integer

Yes

-

The retrieval priority. A non-negative integer. 0 is the highest priority. The system selects documents from higher-priority paths first for final ranking.

quota

Integer

Yes

-

The maximum number of documents retrieved by this path. A non-negative integer.

qp

String

No

Default console rule

The query analysis configuration names, separated by commas (,).

first_rank_name

String

No

Default console configuration

The basic ranking configuration name.

second_rank_name

String

No

Default console configuration

The business ranking configuration name.

total_rank_size

Integer

No

Engine default

The total number of documents for basic ranking. Valid range: [1, 5000000].

total_rerank_size

Integer

No

Engine default

The total number of documents for business ranking. Valid range: [1, 10000].

sort

String

No

-RANK

The sort clause. For syntax, see Global sorting: sort clause.

filter

String

No

""

The filter clause. For syntax, see Result filtering: filter clause.

kvpairs

Map

No

{}

Custom key-value pairs. For usage details, see Custom parameter passing - kvpair clause.

Sample code

Sample request

The following example shows a request with three query paths:

  • main path: highest priority, uses the sys_title query analysis rule.

  • sub path: second-highest priority, with no query analysis rule.

  • main/vector path: A vector query is derived because text embedding is configured in the query analysis rule for the main path.

{
    "queries": [
        {
            "query": "title:'AI'",
            "path": "sub",
            "priority": 2,
            "quota": 100,
            "qp": ""
        },
        {
            "query": "title:'OpenSearch'",
            "path": "main",
            "priority": 1,
            "quota": 100,
            "qp": "sys_title"
        }
    ],
    "raw_query": "OpenSearch",
    "start": 0,
    "hit": 10,
    "format": "fulljson",
    "trace": "debug",
    "rank_trace": "info",
    "unified_rank_type": "rrf",
    "unified_rank_size": 1000,
    "fetch_fields": "title",
    "user_id": "123",
    "vector_search": {
        "vector": {
            "top_n": 100,
            "namespaces": [],
            "threshold": 0.5,
            "search_params": {
                "qc_scan_ratio": 0.01
            }
        }
    }
}

Sample response

{
    "errors": [
        {
            "code": 2112,
            "message": "Specified index not in query:text_relevance(title,default,true)"
        }
    ],
    "ops_request_misc": "%7B%22request%5Fid%22%3A%22176129335716862423300005%22%2C%22scm%22%3A%2220140713.120141928..%22%7D",
    "request_id": "176129335716862423300005",
    "result": {
        "compute_cost": [
            {
                "index_name": "test",
                "value": 13.73
            }
        ],
        "facet": [],
        "items": [
            {
                "attribute": {
                    "pk": [
                        "120142134_1"
                    ]
                },
                "fields": {
                    "title": "OpenSearch Industry Algorithm Edition"
                },
                "property": {},
                "sortExprValues": [
                    "0.0327869"
                ],
                "tracerInfo": "begin search path[main] rank trace:\nend search path[main] rank trace.\n\nbegin search path[main/vector] rank trace:\nend search path[main/vector] rank trace.\n",
                "variableValue": {}
            },
            {
                "attribute": {
                    "pk": [
                        "120142134_2"
                    ]
                },
                "fields": {
                    "title": "OpenSearch Retrieval Engine Edition"
                },
                "property": {},
                "sortExprValues": [
                    "0.0322581"
                ],
                "tracerInfo": "begin search path[main] rank trace:\nend search path[main] rank trace.\n\nbegin search path[main/vector] rank trace:\nend search path[main/vector] rank trace.\n",
                "variableValue": {}
            },
            {
                "attribute": {
                    "pk": [
                        "120142134_3"
                    ]
                },
                "fields": {
                    "title": "AI Search Open Platform"
                },
                "property": {},
                "sortExprValues": [
                    "0.0163934"
                ],
                "tracerInfo": "begin search path[sub] rank trace:\nend search path[sub] rank trace.\n",
                "variableValue": {}
            }
        ],
        "num": 3,
        "searchtime": 0.085292,
        "total": 3,
        "viewtotal": 3
    },
    "status": "OK",
    "tracer": ""
}

Response parameters

Parameter

Type

Description

status

string

The execution result. OK indicates success and FAIL indicates failure. Troubleshoot based on the returned error code.

request_id

string

The query record ID, primarily used for troubleshooting.

result

string

The actual returned results, including the query time searchtime, total number of engine results total, number of results returned by this request num, maximum number of results returned by this query viewtotal, query results items, aggregation results facet, and scorllid.

errors

string

The error details. error_message represents the error message. For the meaning of error_code, see the Error codes topic.

  • searchtime:The engine processing time, in seconds.

  • Differences between total, viewtotal, and num:total is the number of engine results that match the query, without considering the config clause. This value is optimized for large result sets. For performance and relevance, the engine returns at most viewtotal results. For pagination, start+hit must be less than viewtotal. total is generally used for display. num is the number of entries actually returned by this query request, subject to start and hit in the config clause, and does not exceed hit.

  • compute_cost: An array with one map element. index_name is the application ID and value is the LCU consumed by this query.

  • items:Contains the retrieved query data. fields contains the retrieved search content.

  • variableValue:The returned value of a custom parameter, such as distance. The variableValue node is displayed only when config clause format is xml or fulljson; it is not displayed by default in json format.

  • sortExprValues: The ranking score of the corresponding document.

  • facet:Stores information returned by the Aggregate clause.

  • ARRAY field type: Returned in JSON and fulljson formats with values separated by \t; in xml format, values are separated by spaces.

Multi-path query processing

  1. Parallel queries: Process every query in parallel. Determine the number of documents for each path from its quota, using the quota by default and no more than 5000. Send the queries to the engine to obtain candidate document IDs from each path.

  2. Candidate selection: Select up to quota documents from each path in priority order. Stop if the selected total exceeds unified_rank_size.

  3. Candidate ranking:

    1. If unified_rank_type=cava_script, send all document IDs to the engine for ranking.

    2. If unified_rank_type=rrf, rank directly with RRF.

    3. If unified_rank_type=none, skip reranking.

  4. Return results:

    1. If reranking was performed, select the document range defined by start and hit. If reranking was skipped (unified_rank_type=none), return the complete candidate set and ignore start and hit.

      Important

      When unified_rank_type is none, the system skips unified sorting, ignores the start and hit pagination parameters, and returns the complete candidate set. This mode may return a large volume of data. We recommend it only if you need to implement ranking outside OpenSearch.

    2. Send the result document IDs to the engine to retrieve the complete documents and return them to the user.

Limits

  • The aggregation, distinct, and highlighting features are not supported.

  • Path limit: A request supports up to five retrieval paths. Derived vector queries are not counted separately.

  • Application restriction: This feature supports only exclusive applications.

  • Retrieval limit: Each path can retrieve at most 5000 candidate documents from the engine.