Add the @searchable
directive to an @model
type to enable OpenSearch-based data search and result aggregations. This gives you the ability to:
and
/or
/not
conditionsSearch and filter dataOnce the
@searchable
directive is added, all new records added to the model are streamed to OpenSearch. To backfill existing data, see Backfill OpenSearch index from DynamoDB table.
Every model with a @searchable
directive attached generates a new "search" GraphQL query to search and filter for records. The example above provides you the ability to search for "Student" records using a "searchStudents" query.
The filter
parameter allows you to filter for records based on their field values.
In the example above, the search result consists of students with the name "Rene Brandel"
Supported search operations Nested search conditions (and, or, not)Use the filter parameter to pass a nested and
/or
/not
condition.
By default, every operation in the filter properties is and
ed. Use the or
or not
properties in the search query's filter
parameter to override this behavior.
The query above returns a "Student" if:
and
or
Use the sort
parameter to sort your search results by a field in ascending or descending order. The field
argument accepts any field available on the model. The direction
accepts either asc
or desc
.
In the example above, the search result is sorted based on their name
in a desc
ending order.
To sort over multiple fields, provide array of sort conditions. When sorting over multiple fields, the sort conditions are applied in the sort
array's order.
In the example above, the search result is first sorted by name
in a desc
ending order and then by dateOfBirth
in an asc
ending order.
By default, the search result page size is 100. To customize the page size modify the limit
parameter. Query for the nextToken
and use it in your subsequent pagination requests:
Add the total
field in your query response to get the total count of search result hits.
In the example above, the response's total
field contains the total search result count for "Students" whose name ends with "Brandel". Note: total
is calculated based on all records, irrespective of pagination configurations.
Use the aggregates
parameter to get aggregate values such as "minimum", "maximum", "average", and "sum" returned in the aggregateItems
field. Note: aggregates
are calculated based on all records, irrespective of pagination configurations.
Provide the min
value as the aggregate
type
and specify the aggregateItems
in the response field.
In the example above, the response includes the minimum value of "examsCompleted" for all Students whose name starts with "Rene".
Provide the max
value as the aggregate
type
and specify the aggregateItems
in the response field.
In the example above, the response includes the maximum value of "examsCompleted" for all Students whose name starts with "Rene".
Provide the avg
value as the aggregate
type
and specify the aggregateItems
in the response field.
In the example above, the response includes the average value of "examsCompleted" for all Students whose name starts with "Rene".
Provide the sum
value as the aggregate
type
and specify the aggregateItems
in the response field.
In the example above, the response includes the sum of all "examsCompleted" values for all Students whose name starts with "Rene".
Provide the terms
value as the aggregate
type
and specify the aggregateItems
in the response field.
In the example above, the response includes the terms for the description and their count:
Set up OpenSearch for production environmentsBy default, Amplify CLI will configure a t2.small instance type. This is great for getting started and prototyping but not recommended to be used in the production environment per the OpenSearch best practices.
To configure the OpenSearch instance type per environment:
amplify env add
to create a new environment (e.g. "prod")amplify/team-provider-info.json
file and set OpenSearchInstanceType
to the instance type that works for your applicationamplify push
Learn more about Amazon OpenSearch Service instance types here.
How it worksThe @searchable
directive streams the data of an @model type to Amazon OpenSearch Service and configures search resolvers to query against OpenSearch.
Type definition of the @searchable
directive:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4