To use OpenSearch's algorithm features in search requests, pass the required custom parameters through the SDK for Java. This page lists the parameters for each algorithm module and shows how to set them in your code.
All code examples are pseudocode.
Query analysis
Query analysis powers text vectorization and named entity recognition (NER).
| Parameter | Required | Description |
|---|---|---|
raw_query |
Yes | The original search query string. Used by the text vectorization and NER models. |
...
// Create a SearchParams object.
SearchParams searchParams = new SearchParams(config);
searchParams.setQuery("default:'OpenSearch'");
// Set the raw_query parameter.
Map<String, String> customParam = new HashMap<>();
customParam.put("raw_query", "OpenSearch");
searchParams.setCustomParam(customParam);
// Run the query and return the results as a SearchResult object.
SearchResult execute = searcherClient.execute(searchParams);
...
Category prediction
Category prediction uses raw_query to train algorithm models such as category prediction models.
| Parameter | Required | Description |
|---|---|---|
raw_query |
Yes | The original search query string. Used to train category prediction models. |
...
// Create a SearchParams object.
SearchParams searchParams = new SearchParams(config);
searchParams.setQuery("default:'Apple'");
// Set the raw_query parameter.
Map<String, String> customParam = new HashMap<>();
customParam.put("raw_query", "Apple");
searchParams.setCustomParam(customParam);
// Run the query and return the results as a SearchResult object.
SearchResult execute = searcherClient.execute(searchParams);
...
Drop-down suggestions
Three parameters control drop-down suggestion behavior. Pass them in combination depending on the capabilities you want to enable:
| Parameter | Required | Description |
|---|---|---|
raw_query |
Yes | The original search query string. Enables high-frequency queries in drop-down suggestions. |
from_request_id |
No | The request ID from the preceding search. Optimizes the drop-down suggestion ranking model and enables tracking of suggestion-guided search metrics. |
user_id |
No | The user identifier. Pass together with raw_query and from_request_id to enable intelligent sorting. Pass in the suggestion request (via SuggestParams) to enable search history. |
Intelligent sorting — pass raw_query, user_id, and from_request_id in the search request:
...
// Create a SearchParams object.
SearchParams searchParams = new SearchParams(config);
searchParams.setQuery("default:'Apple'");
// Set raw_query, user_id, and from_request_id to enable intelligent sorting.
Map<String, String> customParam = new HashMap<>();
customParam.put("raw_query", "Apple");
customParam.put("user_id", "12345");
customParam.put("from_request_id", "159851481919726888064081");
searchParams.setCustomParam(customParam);
// Run the query and return the results as a SearchResult object.
SearchResult execute = searcherClient.execute(searchParams);
...
Search history — pass raw_query in the search request and user_id in the suggestion request:
...
// Create a SearchParams object.
SearchParams searchParams = new SearchParams(config);
searchParams.setQuery("default:'Apple'");
// Set raw_query in the search request.
Map<String, String> customParam = new HashMap<>();
customParam.put("raw_query", "Apple");
searchParams.setCustomParam(customParam);
// Run the query and return the results as a SearchResult object.
SearchResult execute = searcherClient.execute(searchParams);
...
// Set user_id in the suggestion request to enable search history.
SuggestParams suggestParams = new SuggestParams();
suggestParams.setUserId("12345");
Top searches and hints
Top searches and hints use raw_query to train algorithm models such as top search models and hint models. Pass from_request_id and user_id to improve ranking and collect guidance metrics.
| Parameter | Required | Description |
|---|---|---|
raw_query |
Yes | The original search query string. Used to train top search and hint models. |
from_request_id |
No | The request ID from the preceding search. Improves top search and hint ranking and enables tracking of hot search- and hint-guided search metrics. |
user_id |
No | The user identifier. Pass together with from_request_id to enable tracking of hot search- and hint-guided search metrics. |
...
// Create a SearchParams object.
SearchParams searchParams = new SearchParams(config);
searchParams.setQuery("default:'Apple'");
// Set raw_query, user_id, and from_request_id.
Map<String, String> customParam = new HashMap<>();
customParam.put("raw_query", "Apple");
customParam.put("user_id", "12345");
customParam.put("from_request_id", "160851481919726888064913");
searchParams.setCustomParam(customParam);
// Run the query and return the results as a SearchResult object.
SearchResult execute = searcherClient.execute(searchParams);
...
Cava-based plug-in
The Cava-based plug-in applies a custom second-phase ranking policy using a Cava script. Set two values on the Rank object: the script name and the sort type.
| Parameter | Required | Description |
|---|---|---|
| Cava script name | Yes | The name of the Cava script to invoke for second-phase ranking. Set via setSecondRankName. |
| Sort type | Yes | The ranking method. Set to RankType.CAVA_SCRIPT to use Cava script-based ranking. Set via setSecondRankType. |
...
// Create a SearchParams object.
SearchParams searchParams = new SearchParams(config);
...
// Create a Rank object and configure Cava script-based ranking.
Rank rank = new Rank();
rank.setSecondRankName("test_cava");
rank.setSecondRankType(RankType.CAVA_SCRIPT);
// Apply the ranking policy to the search request.
searchParams.setRank(rank);