You can configure default display fields to specify the fields in the application schema that need to be retrieved and returned for each search request. Use the fetch_fields parameter to specify only the fields your application needs to display.
How it works
Two configuration layers control which fields are returned:
| Layer | When it applies |
|---|---|
| Console default | No fetch_fields value is passed in the request |
SDK/API fetch_fields | A value is passed at query time — overrides the console default |
Set default display fields in the console
Log on to the OpenSearch console. In the left-side navigation pane, choose Feature Extensions > Search Result Display.
In the Default Display Fields section, add the fields to return.
In the Default Display Fields section, click the edit icon at the end of the field list to add or modify display fields.
If you have not set a console default yet, you can also add display fields during a search test for an application.
Note: Separate multiple field values with semicolons (;).
In the search test page, in the parameters area, use the fetch_fields parameter to specify the fields to return. For example, fetch_fields=buy,cate_id,title returns only the buy, cate_id, and title fields.
Override display fields at query time
Passing fetch_fields in an SDK call or API request overrides the console default for that request. Specify only the fields your client needs — the size of returned text data has a significant impact on search performance.
API parameters: See Initiate search requests for how to use the fetch_fields parameter in API calls.
SDK for Java: The following example specifies the fields to return.
// Specify the fields to return in search results.
config.setFetchFields(Lists.newArrayList("id", "name", "phone", "int_arr", "literal_arr", "float_arr", "cate_id"));Limits
JOIN multi-table scenarios: Primary key fields in secondary tables cannot be set as default display fields. To include secondary table primary key values in search results, use the associated fields in the primary table instead.
For example, if the primary table p_table has primary key id and the secondary table s_table_1 has primary key id_1, specifying fetch_fields=id_1 in a search test does not return the secondary table primary key value. Specifying fetch_fields=id (the associated field in the primary table) returns the expected results.