amplify-cli: Appsync cannot sort items by string value with Elasticsearch
Describe the bug
I’m using amplify-cli to generate appsync resolvers with @searchable directive, but it seems that search resolver cannot sort items by String value, but it works with AWSDateTime value.
To Reproduce Example request:
{
searchUsers(sort: {
field: fullName,
direction: asc
}) {
items {
id
fullName
}
}
}
Expected behavior User items sorted by fullName.
Screenshots

Desktop (please complete the following information):
- Using AWS Console
Smartphone (please complete the following information):
- Using AWS Console
Additional context It also happened to my past appsync project.
You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = ‘DEBUG’; in your app.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 8
- Comments: 15 (2 by maintainers)
@hakimio is right, AWS decided do not overhead it with
fielddata, resouce:Resource: Elasticsearch docs
I guess AWS team decided to use
keywordas mentioned in the docsThis query works perfectly:
I haven’t figured out how to make it work from JS side yet
@ShepelievD The velocity templating language allows you to do a check like if string field array contains sort field, add “.keyword” postfix, otherwise leave it as it is.
You can fix that by modifying the resolver to use “name.keyword” for field name when the field is of string type like I shown in my previous post.