Siddharth
Siddharth

Reputation: 5219

Search modifiers in AWS AppSync and GrahphQL

I am trying to develop a GraphQL API with AWS AppSync + Amplify. My model looks like -

type AudioMetadata @model @searchable {
    id: ID!,
    title: String!,
    description: String!,
    category: [String]!,
    duration: Int!
}

As you can tell, this is backed by DynamoDB and Amazon Elastic Search. I want to have a Query that takes in search modifiers for searching. Search Modifiers are Slack-like modifiers and take the form id:, intitle:, indescription:, duration_lt:, and duration_gt:.

When searching, I'd like to search from ElasticSearch.

My question is how can I write a Query that caters to these search modifiers (maybe take in the search modifier and a search string) and searches against that field in Elastic Search.

Upvotes: 1

Views: 657

Answers (1)

Ashwin Devendran
Ashwin Devendran

Reputation: 421

As user Yik San Chan mentioned in the comments, a great example would be https://aws-amplify.github.io/docs/cli/graphql#add-a-custom-geolocation-search-resolver-that-targets-an-elasticsearch-domain-created-by-searchable

In your case you would have to create additional graphql queries in the schema to handle the various values you want to search by (i.e. intitle, indescription) and create the resolvers for each of these queries. Follow the examples on the link above.

Upvotes: 2

Related Questions