Skip to content

Update @searchable documentation to recommend explicit ElasticSearch Mapping #2035

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

Open
sacrampton opened this issue Jun 18, 2020 · 2 comments
Assignees
Labels
amplify/data Issue related to aws-amplify/amplify-category-api p3 missing info theme:data-searchable

Comments

@sacrampton
Copy link

Is your feature request related to a problem? Please describe.

This is related to aws-amplify/amplify-cli#4436 where the current Lambda sync function from DDB to ES infers data types based on data sent to ES rather than honouring the graphql schema. For example if you have userField01: String and you send a string with the value of "45.71" to ES in the first record it will create userField01: Float in ES - so when you go to send "Test" in the second record it will fail.

I was having records failing so dug into this problem and decided that I needed to create explicit ElasticSearch mappings that aligned with my schema.graphql. I have 44 tables in my database with thousands of fields and have separate dev, test, prod environments. Took a very long time to generate and apply all these ElasticSearch mappings, but the result shocked me. Approximately half of my tables failed to update with the mappings derived from schema.graphql - so I had to re-index those indexes with the correct mappings (see below).

PUT /asset/_mapping/doc
{
  "properties": {
    "id": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "acquisitionDate": {
      "type": "date"
    },
    "acquisitionValue": {
      "type": "float"
    },
    "assetVisitQueue": {
      "type": "integer"
    },
    "auditCompleted": {
      "type": "boolean"
    },
    "geolocation": {
      "type": "geo_point"
    }
  }
}

Describe the solution you'd like
Ideally given the significant vulnerability this introduces for inconsistency between DDB and ES I think Amplify/AppSync should generate an explicit mapping template that aligns with schema.graphql and apply it so that the solution is not open to random data types being inferred.

However, in the absence of this I think there should be very clear warnings in the documentation that there is a high risk of incompatible data types being created between DDB & ES and that if you are using @searchable you MUST manually apply explicit mappings to ElasticSearch.

Describe alternatives you've considered
I solved this using explicit mappings in ES - but is was a MASSIVE amount of work.

@attilah
Copy link
Contributor

attilah commented Jun 18, 2020

@sacrampton thanks for reporting this it seems to be a possible enhancement, documentation and better DX issue. Two of them is easy and simple, the mapping generation is something that requires a bigger effort we'll keep track of this and glad that you put in the hard work and figured it out we appreciate it.

@renebrandel renebrandel transferred this issue from aws-amplify/amplify-cli Jun 30, 2020
@renebrandel renebrandel added the amplify/cli Issues tied to CLI label Jul 1, 2020
@medelman17 medelman17 added this to the Issue Burndown milestone Mar 10, 2021
@renebrandel renebrandel assigned SwaySway and unassigned renebrandel May 21, 2021
@mauerbac mauerbac added the p3 missing info label May 9, 2022
@InnovateWithEric InnovateWithEric added amplify/data Issue related to aws-amplify/amplify-category-api and removed amplify/cli Issues tied to CLI labels May 20, 2022
@brauliolledo
Copy link

+1 to this. We've come across this issue affecting a handful of production environments for our Amplify app and causing some tables to not be indexed and therefore records being missing from queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
amplify/data Issue related to aws-amplify/amplify-category-api p3 missing info theme:data-searchable
Projects
None yet
Development

No branches or pull requests

9 participants