Algorithm module parameters

更新时间:
复制 MD 格式

To use OpenSearch's algorithmic features, you must include the required parameters in your query requests. This topic shows how to add these parameters for each algorithm module by using the Java SDK. All examples are provided in pseudocode.

Query analysis

In the console, on the query test page, expand the search criteria section. In the parameters row, add the raw_query parameter and set its value to your actual query, for example, "OpenSearch".

...
// Search request
SearchParams searchParams = new SearchParams(config);
searchParams.setQuery("default:'OpenSearch'"); // Guided by the suggester
// Add custom parameters
Map<String, String> customParam =new HashMap<>();
customParam.put("raw_query","OpenSearch");
searchParams.setCustomParam(customParam);
// Execute the query and retrieve the search result object
SearchResult execute = searcherClient.execute(searchParams);
...

Category prediction

In the console, select the Ha3 engine and the corresponding application. Expand the search criteria section. In the clause area, set config=start:0,hit:10,format:fulljson. In the parameter area, set raw_query to your actual query, such as "apple". Click Search.

...
// Search request
SearchParams searchParams = new SearchParams(config);
searchParams.setQuery("default:'apple'"); // Guided by the suggester
// Add custom parameters
Map<String, String> customParam =new HashMap<>();
customParam.put("raw_query","apple");
searchParams.setCustomParam(customParam);
// Execute the query and retrieve the search result object
SearchResult execute = searcherClient.execute(searchParams);
...

Suggester

  • raw_query: Enables hot queries.

  • from_request_id: Optimizes the suggester's ranking model to improve search results for queries made from suggestions. This parameter is also used to collect metrics for measuring the effectiveness of the suggester.

  • raw_query, user_id, and from_request_id: Enable intelligent ranking.

...
// Search request
SearchParams searchParams = new SearchParams(config);
searchParams.setQuery("default:'apple'"); // Guided by the suggester
// Add custom parameters
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);
// Execute the query and retrieve the search result object
SearchResult execute = searcherClient.execute(searchParams);
...
  • To enable search history, pass the raw_query parameter in the search request and the user_id parameter in the suggester request.

...
// Search request
SearchParams searchParams = new SearchParams(config);
searchParams.setQuery("default:'apple'"); // Guided by the suggester
// Add custom parameters
Map<String, String> customParam =new HashMap<>();
customParam.put("raw_query","apple");
searchParams.setCustomParam(customParam);
// Execute the query and retrieve the search result object
SearchResult execute = searcherClient.execute(searchParams);
...
// Suggester request
SuggestParams suggestParams = new SuggestParams();
suggestParams.setUserId("12345");

Trending searches and default searches

  • raw_query: Used to train the algorithm model for trending searches and default searches.

  • from_request_id and user_id: Improve the effectiveness of searches guided by trending and default searches. These parameters are also used to collect metrics for measuring the features' effectiveness.

...
// Search request
SearchParams searchParams = new SearchParams(config);
searchParams.setQuery("default:'apple'"); // Guided by the suggester
// Add custom parameters
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);
// Execute the query and retrieve the search result object
SearchResult execute = searcherClient.execute(searchParams);
...

Cava plug-in

  • Cava script name

  • Rank type

On the query debugging page, set the engine type to Ha3 engine, the application name to zy_test, and the environment to Online Application. In the search criteria, add the parameters second_rank_type = cava_script and second_rank_name = test_cava. Enter default:apple as the query, and then click Search.

...
// Create a SearchParams object
SearchParams searchParams = new SearchParams(config);
...
// Create a Rank object
Rank rank=new Rank();
// Specify the Cava script to use
rank.setSecondRankName("test_cava");
// Set the rank type to CAVA_SCRIPT
rank.setSecondRankType(RankType.CAVA_SCRIPT);
// Add the Rank object to the SearchParams object
searchParams.setRank(rank);