如何在速度模板中使用字符串替换(AWS appsync + elasticsearch)?

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

我正在编写一个appsync查询,以通过弹性从电话号码中搜索记录(使用速度模板)。

存储在弹性体上的数据的格式为“ 0123456789”,但请求的格式可以为“ 012-123-1234”。因此,我打算使用字符串替换功能来删除“-”字符。但是,我的代码返回以下错误:

"message": "Lexical error, Encountered: \" _ \ "(95), after: \". \ "at * unset * [line 11, column 51]"

我不确定我的写作是否正确,请帮助。

这是我的代码:

{
    "version":"2017-02-28",
    "operation":"GET",
    "path":"/res/res/_search",
    "params":{
        "headers":{},
        "queryString":{},
        "body":{
            "from":$util.defaultIfNull($ctx.args.nextToken, 0),
            "size":$util.defaultIfNull($ctx.args.limit, 20),
            "query": {
                 "match": { "phoneNumber": "$context.args.phoneNumber".replace('-', '') }
            }
        }
    }
}
amazon-web-services elasticsearch variadic-templates aws-appsync
1个回答
0
投票

嗯,我发现了错误,这是“字符的位置错误。

"match": { "phoneNumber": "$context.args.phoneNumber".replace('-', '') }

=>

"match": { "phoneNumber": "$context.args.phoneNumber.replace('-', '')" }
© www.soinside.com 2019 - 2024. All rights reserved.