amplify-category-api icon indicating copy to clipboard operation
amplify-category-api copied to clipboard

Cannot use enums to sort @searchable search results

Open Jupdi opened this issue 2 years ago • 3 comments

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

No response

Amplify CLI Version

11.0.4

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

None

Describe the bug

I cannot use enums to sort my search results using graphql, and they are not beeing generated in to he SortableFields.

Expected behavior

Use enums to sort, like using other types of fields.

Reproduction steps

  1. Create a type with @searchable
  2. Add a field with type enum
  3. Push some data into Opensearch
  4. Using the seach query to search for some of the data
  5. Try to use the enum field to sort

Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • [X] I have removed any sensitive information from my code snippets and submission.

Jupdi avatar Jun 09 '23 10:06 Jupdi

I could fix the problem by manually add the SortableFields Enum to my schema and add the missing fields, but now i need to manually keep that in sync.

Jupdi avatar Jun 09 '23 11:06 Jupdi

Hi @Jupdi, Thank you for bringing this to our attention.We greatly appreciate your proactive approach in resolving the problem by manually adding the missing fields to the SortableFields enum in the schema. We have successfully reproduced the problem by following the steps outlined in the description. As a result, we have categorized this as a bug and will further investigate it with our team.

schema used:

type Post @model @searchable {
  postId: ID!
    @primaryKey(sortKeyFields: ["title"])
    @index(name: "postByPostId", sortKeyFields: ["title"])
  title: String!
  comments: [Comment] @hasMany(indexName: "byPost", fields: ["postId", "title"])
  posttype: PostType
}

type Comment @model {
  commentId: ID! @primaryKey(sortKeyFields: ["content"])
  content: String!
  postId: ID @index(name: "byPost", sortKeyFields: ["postTitle"]) # customized foreign key for parent primary key
  postTitle: String # customized foreign key for parent sort key
  post: Post @belongsTo(fields: ["postId", "postTitle"])
}

enum PostType {
  newsletter
  blog
}
image

AnilMaktala avatar Jun 09 '23 13:06 AnilMaktala

Any update? Surprised that we can't sort by enums...

cjsilva-umich avatar Aug 01 '23 21:08 cjsilva-umich