question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Appsync cannot sort items by string value with Elasticsearch

See original GitHub issue

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 image

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:15 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ShepelievDcommented, May 14, 2019

@hakimio is right, AWS decided do not overhead it with fielddata, resouce:

Fielddata can consume a lot of heap space, especially when loading high cardinality text fields. Once fielddata has been loaded into the heap, it remains there for the lifetime of the segment. Also, loading fielddata is an expensive process which can cause users to experience latency hits. This is why fielddata is disabled by default.

Resource: Elasticsearch docs

I guess AWS team decided to use keyword as mentioned in the docs

This query works perfectly:

GET your_pefect_index/_search
{
  "sort": [
      {
        "your_pefect_field.keyword": {
          "order": "asc"
        }
      }
    ]
}

I haven’t figured out how to make it work from JS side yet

1reaction
hakimiocommented, May 23, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

AppSync - query for all items created within a date range?
Which returns all notes that match the UTC time with that string prefix. From which, I have to sort myself using moment.diff(), or...
Read more >
Sort search results | Elasticsearch Guide [8.5] | Elastic
Allows you to add one or more sorts on specific fields. Each sort can be reversed as well. The sort is defined on...
Read more >
Integrating alternative data sources with AWS AppSync
This function will modify our Redis sorted set by adding or updating restaurant data, specifically latitude and longitude. Generating ...
Read more >
API (GraphQL) - Search and result aggregations - Amplify Docs
... get aggregation values, such as sum, average, min, max, terms; retrieve total search result count; sort the search results across one or...
Read more >
Finding the nearest locations around you using AWS Amplify
name: String! ... In order to access your Amazon Elasticsearch domain, you can run the ... This will open the AWS AppSync console...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found