A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.amplify.aws/gen1/javascript/build-a-backend/graphqlapi/search-and-result-aggregations/ below:

Website Navigation


Build search and aggregate queries - JavaScript

Build search and aggregate queries

Add the @searchable directive to an @model type to enable OpenSearch-based data search and result aggregations. This gives you the ability to:

Once 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.

Search and filter data

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 anded. Use the or or not properties in the search query's filter parameter to override this behavior.

The query above returns a "Student" if:

Sort search results

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 descending order.

Sort search result over multiple fields

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 descending order and then by dateOfBirth in an ascending order.

Paginate over search results

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:

Total count of search results

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.

Aggregate values for search result (minimum, maximum, average, sum, terms)

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 environments

By 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:

  1. Run amplify env add to create a new environment (e.g. "prod")
  2. Edit the amplify/team-provider-info.json file and set OpenSearchInstanceType to the instance type that works for your application
  1. Deploy your changes with amplify push

Learn more about Amazon OpenSearch Service instance types here.

How it works

The @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