amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

@searchable directive does not index existing documents

Open chrisco512 opened this issue 8 years ago • 15 comments

Do you want to request a feature or report a bug? Bug

What is the current behavior? When adding @searchable directive to an existing model (one with entries already in Dynamo), the ElasticSearch service does not index existing documents. It will only index new documents added after the @searchable directive is added.

Steps to reproduce the issue:

  1. Create a model in /amplify/backend/api/schema.graphql
  2. Use amplify push to deploy CloudFormation template and publish API
  3. Use AppSync GraphQL explorer to create new documents for that model
  4. Go back to schema.graphql file and add @searchable directive
  5. Use amplify push to update resources

What is the expected behavior? Elasticsearch service should index all existing documents for a given model, and not just new ones.

Additional environment details

  • OS version (ie Windows 10 build X, macOS Sierra 10.12.6, etc.): Ubuntu 18, Node v.8.9.3
  • Output of amplify --version: 0.1.16
  • Did this work in previous versions?: N?

chrisco512 avatar Sep 03 '18 09:09 chrisco512

This is a feature request. Backfilling data is a goal in the future but is not immediately in scope.

mikeparisstuff avatar Sep 06 '18 18:09 mikeparisstuff

+1. I am running into this too. Is there a workaround in the meantime like using https://www.npmjs.com/package/dynamodb-to-elasticsearch to backfill the data?

hisham avatar Nov 30 '18 16:11 hisham

+1 for this feature. Is there an easy way to manually do this?

EdwardFinegan avatar Mar 15 '19 16:03 EdwardFinegan

@mikeparisstuff +1 for the feature.

artista7 avatar Apr 24 '19 12:04 artista7

+1 for this feature.

ade-fatimah avatar May 23 '19 19:05 ade-fatimah

+1 for this feature

claytonrogers avatar Jul 02 '19 01:07 claytonrogers

+1 enterprise must-have.

monaye avatar Jul 11 '19 19:07 monaye

If you have DDB Stream -> Lambda -> ES setup then you could easily add a field e.g. 'migration_run:1' to all existing records in a DynamoDB table to stream it to Elastic? Put some throttling or scheduling in place to not impact normal operation. That's how AWS would do it 😆

aldegoeij avatar Aug 30 '19 15:08 aldegoeij

Any updates on this? Without this, it makes it pretty hard to use @ searchable. Even if we had a manual workaround that would be great.

malcomm avatar Feb 13 '20 22:02 malcomm

@malcomm The fix is fairly simple. Create a migration Lamda function. Query all documents (or query a batch and re-run). Make it update one "migration" field in each document. DynamoDB will then sync the entire document to Elasticsearch. You can then delete the "migration" field or keep it around for a future DB migration.

houmark avatar Feb 13 '20 22:02 houmark

Hi everyone - we've added a section in our documentation explaining how to backfill existing data https://docs.amplify.aws/cli/graphql-transformer/directives#backfill-your-elasticsearch-index-from-your-dynamodb-table

renebrandel avatar Apr 24 '20 18:04 renebrandel

Thanks @brene the script works beautifully! For anyone looking to put together the script by brene, you can find the Lambda function ARN in AWS > Services > Lambda. There really is a lambda generated called DdbToEsFn to my surprise as I didn't know since it was auto-generated. Also, you can find the Event source ARN in AWS > DynamoDB > <Your Table> > Overview Tab > Stream details

clodal avatar Jun 05 '20 11:06 clodal

It would be even better if the CLI did this easily via something like: amplify api reindex

  • Delete Existing indexes
  • Repush all @searchable fields via the above lambda
  • Cleanup

GeorgeBellTMH avatar Jun 05 '20 12:06 GeorgeBellTMH

I'm confused... the docs link back to this issue, but the issue is now closed? Will CLI integration be coming, or is the python script it for now?

mattfysh avatar May 21 '21 07:05 mattfysh

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[bot] avatar Jun 20 '21 08:06 github-actions[bot]