All Products
Search
Document Center

OpenSearch:Query drop-down suggestions

Last Updated:Mar 08, 2023

The drop-down suggestion feature is a basic feature of OpenSearch. This feature provides recommended search queries for you to select when you enter a search query. You may find the expected search query before you enter the full content of the search query. This helps you obtain the expected search results as soon as possible. The drop-down suggestion feature of OpenSearch supports Chinese character prefixes, full pinyin spelling, and first letters of the abbreviated pinyin spelling. This helps you implement intelligent search recommendation based on the entered content. To configure personalized drop-down suggestions for your business, you need to complete simple configurations in the OpenSearch console. In addition, the OpenSearch console allows you to configure blacklists and search recommendations. This helps you further control and personalize drop-down suggestions. For more information about how to use drop-down suggestions, see Drop-down suggestions.

URL

/v3/openapi/apps/{appName}/suggest/{suggestName}/search
  • Replace the appName parameter with the name of your OpenSearch application.

  • Replace the suggestName parameter with the name of your drop-down suggestion model.

  • The sample URL omits information such as parameters in the request header and the encoding method.

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

Supported format

JSON

Supported HTTP request method

GET

Request parameters

Parameter

Type

Required

Valid value

Default value

Description

query

STRING

Yes

The query keywords. If the keywords contain Chinese characters, perform URL encoding on the value of this parameter.

hit

INT

No

[1-10]

10

The number of drop-down suggestions to be displayed.

user_id

STRING

No

The ID of the user who sends the current request for drop-down suggestions. Perform URL encoding on the value of this parameter. We recommend that you use the value of the user_id parameter in API requests that are sent to search for data. For more information, see Initiate search requests.

re_search

STRING

No

Specifies whether to retrieve documents by replacing terms in search queries with homophones. By default, this feature is enabled. To disable this feature, set the re_search parameter to disable.

Note: The query parameter in API requests for drop-down suggestions is different from the query parameter in API requests for data searching. The query parameter in API requests for drop-down suggestions indicates the text that a user enters in the search box. The text does not need to be an index field name.

Response parameters

Parameter

Type

Description

request_id

STRING

The ID of the request, which is used for troubleshooting.

searchtime

FLOAT

The period of time that was taken by the engine to complete the query, in units of seconds.

suggestions

ARRAY

The matched drop-down suggestions. Each element in this array is a drop-down suggestion.

errors

ARRAY

The error information, in which the message parameter indicates the error message. For more information about error codes, see Error codes.

Examples

A sample API request for drop-down suggestions, which omits information such as parameters in the request header and the encoding method:

http://$host/v3/openapi/apps/app_demo/suggest/suggest_demo/search?hit=10&query=One-piece dress&user_id=xxx

A sample success response:

{
    "request_id": "150116615820104116121674",
    "searchtime": 0.002654,
    "suggestions": [
        {
            "suggestion": "One-piece dress"
        },
        {
            "suggestion": "One-piece dress for Spring"
        },
        {
            "suggestion": "One-piece dress for art enthusiasts"
        }
    ]
}

A sample error response:

{
    "request_id": "150116635320104116122572",
    "searchtime": 0.037484,
    "suggestions": [],
    "errors": [
        {
            "code": 2551,
            "message": "suggester not found"
        }
    ]
}