graphqlaws-amplifyaws-appsync

Unable to return any data in AppSync console with search - using @searchable directive in Amplify


I've added a @searchable directive to my Amplify/GraphQL schema as follows:

type Card
  @model 
  @searchable 
  {
    name: String
    id: ID!
  }

I've added some items, which I can retrieve with listCards in my AppSync Console:

query MyQuery {
  listCards {
    items {
      name
    }
  }
}

# Returns:
{
  "data": {
    "listCards": {
      "items": [
        {
          "name": "hunter"
        },
        {
          "name": "url1"
        },
        {
          "name": "testThur"
        },
        {
          "name": "testThur2"
        },
...
}

Now, when I try to use searchCards I can't get it to return anything:

query MyQuery {
  searchCards(filter: {name: {ne: "nonsense"}}) {
    nextToken
    total
    items {
      name
    }
  }
}

# Returns:
{
  "data": {
    "searchCards": {
      "nextToken": null,
      "total": null,
      "items": []
    }
  }
}

How do I get this working?


Solution

  • I noticed that new cards that I add are returned, but ones that were added before adding the @searchable directive don't get returned.

    There's a grey info paragraph in the docs https://docs.amplify.aws/cli/graphql/search-and-result-aggregations/:

    Once the @searchable directive is added, all new records added to the model are streamed to OpenSearch. To backfill existing data, see Backfill OpenSearch index from DynamoDB table.

    It looks like any previous items that I've created on the database won't be streamed to OpenSearch, and therefore won't be returned by 'search' AppSync calls.

    We're directed here: https://docs.amplify.aws/cli/graphql/troubleshooting/#backfill-opensearch-index-from-dynamodb-table

    We are instructed to use the provided python file with this command:

    python3 ddb_to_es.py \
      --rn 'us-west-2' \ # Use the region in which your table and OpenSearch domain reside
      --tn 'Post-XXXX-dev' \ # Table name
      --lf 'arn:aws:lambda:us-west-2:<...>:function:amplify-<...>-OpenSearchStreamingLambd-<...>' \ # Lambda function ARN, find the DynamoDB to OpenSearch streaming functions, copy entire ARN
      --esarn 'arn:aws:dynamodb:us-west-2:<...>:table/Post-<...>/stream/2019-20-03T00:00:00.350' # Event source ARN, copy the full DynamoDB table ARN
    

    (I've tried this with my region, ARN's, and DynamoDB references but when I hit enter in my CLI it just goes to the next command line and nothing happens? I've not used python before. Hopefully someone here has more luck?)