All Products
Search
Document Center

Query drop-down suggestions

Last Updated: Sep 09, 2021

The drop-down suggestion feature is a basic feature of OpenSearch. This feature provides recommended search queries for users to select when they enter a search query. Users may find the expected search query before they enter the full content of the search query. This helps them 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 API operation for data searching.

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

string

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&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"
        }
    ]
}