无法通过搜索在 AppSync 控制台中返回任何数据 - 在 Amplify 中使用 @searchable 指令

问题描述 投票:0回答:3

我已将 @searchable 指令添加到我的 Amplify/GraphQL 架构中,如下所示:

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

我添加了一些项目,可以使用 AppSync 控制台中的 listCards 检索这些项目:

query MyQuery {
  listCards {
    items {
      name
    }
  }
}

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

现在,当我尝试使用

searchCards
时,我无法让它返回任何内容:

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

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

如何让它发挥作用?

graphql aws-amplify aws-appsync
3个回答
0
投票

我注意到我添加的新卡会被返回,但在添加 @searchable 指令之前添加的卡不会被返回。

文档中有一个灰色信息段落https://docs.amplify.aws/cli/graphql/search-and-result-aggregations/:

添加 @searchable 指令后,添加到模型中的所有新记录都会流式传输到 OpenSearch。要回填现有数据,请参阅从 DynamoDB 表回填 OpenSearch 索引。

看起来我之前在数据库中创建的任何项目都不会流式传输到 OpenSearch,因此不会由“搜索”AppSync 调用返回。

我们被定向到这里:https://docs.amplify.aws/cli/graphql/troubleshooting/#backfill-opensearch-index-from-dynamodb-table

我们被指示通过此命令使用提供的 python 文件:

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

(我已经在我的区域、ARN 和 DynamoDB 引用中尝试过此操作,但是当我在 CLI 中按 Enter 键时,它只是转到下一个命令行,没有任何反应?我以前没有使用过 python。希望这里有人有更多运气?)


0
投票

您应该像这样运行脚本:

python3 fileNameToYourScript.py --rn <region> --tn <fullTableName> --lf <arnToYourOpenSearchLambdaFunction>  --esarn <arnToYourTableName>

删除尖括号并将其替换为实际值(不带引号)...

另一件事,我一直收到无法找到凭证的错误,如果您也收到它,我通过转到 .aws/credentials 并复制我的个人资料详细信息但将副本命名为 [default] 来修复它。在 .aws/config 中也做了同样的事情,复制我的区域详细信息并命名副本[默认]。


0
投票

你解决问题了吗? 我正在做同样的事情。我已经在 OpenSearch 上回填了文档,但查询不断发送空的项目数组。

© www.soinside.com 2019 - 2024. All rights reserved.