Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting+Limit with AppSync + Elastic Search #5795

Closed
chantlong opened this issue Nov 6, 2020 · 3 comments
Closed

Sorting+Limit with AppSync + Elastic Search #5795

chantlong opened this issue Nov 6, 2020 · 3 comments
Labels
pending-response Issue is pending response from the issue author pending-triage Issue is pending triage @searchable Issues related to the @searchable GraphQL directive

Comments

@chantlong
Copy link

chantlong commented Nov 6, 2020

With AppSync <-> Elastic Search, according to the docs, it advises you to use filter when searching for a specific term.
https://docs.amplify.aws/cli/graphql-transformer/searchable

If I have a 100 posts and post #1, #2, #100 have my type === 'blog', I expect to get 3 results back if I search by type === 'blog' and limit at 5 with Elastic Search using the following query. But I get back actually 1 result.

If I remove thesort: {direction: desc, field: time} I get back all 3 results.

query MyQuery {
  searchList(sort: {direction: desc, field: time}, limit: 5, filter: {
    type: {
      matchPhrase: "blog"
    }
  }) {
    items {
      id
      type
    }
  }
}

I think the issue is with filter because it searches then filters.

With AppSync <-> DynamoDB, in the schema.graphql you can add the keys attribute to create a GSI, so when you query, you don't need to use the filter key, but in the root of the query specify the attribute you added as a key. This fixes the LIMIT issue in the AppSync <-> DynamoDB scenario.

How do I fix this issue with the AppSync <-> ElasticSearch scenario?

@akshbhu akshbhu added @searchable Issues related to the @searchable GraphQL directive pending-triage Issue is pending triage labels Nov 6, 2020
@akshbhu
Copy link
Contributor

akshbhu commented Nov 9, 2020

Hi @chantlong

It seems like there is no value with just blog keyword present in your inverted index in ES. Values like blog1 or blog2 wont be fetched using just matchphrase as it will look for blog keyword in your index.

Can you try with matchPhraseprefix?

Let me know if this works for you?

@akshbhu akshbhu added pending-response Issue is pending response from the issue author pending-close-response-required labels Nov 9, 2020
@chantlong
Copy link
Author

@akshbhu "blog" is just a text example, it can be anything. type has "blog", "business", "finance"...etc.

Anyways it seemed like there was a problem with the resolvers generated by Amplify in that it causes the search, to search the entire Table with the matched text and then filtered by user Id in the resolver. Managed to be fixed with a custom resolver so that it queries results only belong to that user id without filtering needed.

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pending-response Issue is pending response from the issue author pending-triage Issue is pending triage @searchable Issues related to the @searchable GraphQL directive
Projects
None yet
Development

No branches or pull requests

2 participants