【发布时间】:2021-02-13 09:08:44
【问题描述】:
我正在尝试通过 VTL AppSync 解析器对 ElasticSearch 索引执行批量操作。
特别是这个突变:
input CreateTopicsInput {
language: String!
texts: [String!]!
}
type Mutation {
createTopics(input: CreateTopicsInput!): [Topic!]
}
我创建了以下解析器: Mutation.createTopics.req.vtl
#set( $body = "" )
#set( $q = '"' )
#foreach( $text in $ctx.args.input.texts )
#set( $body = $body.concat("{ ${q}index${q}: { ${q}_id${q}: ${q}${text}${q} } }
") )
#set( $body = $body.concat("{ ${q}text${q}: ${q}$text${q}, ${q}suggest${q}: { ${q}input${q}: ${q}$text${q} } }
") )
#end
{
"version": "2017-02-28",
"operation": "POST",
"path": "/topic-${ctx.args.input.language}/doc/_bulk",
"params": {
"headers" : [ { "Content-Type" : "application/x-ndjson" } ],
"body": "$body"
}
}
例如,当使用此数据执行时:
mutation CreateTopic {
createTopics(input: {
language: "en",
texts: [ "COVID", "Election" ]}) {
text
}
}
似乎输出了正确的调用:
{
"version": "2017-02-28",
"operation": "POST",
"path": "/topic-en/doc/_bulk",
"params": {
"headers" : [ { "Content-Type" : "application/x-ndjson" } ],
"body": "{ "index": { "_id": "COVID" }
{ "text": "COVID" }
{ "index": { "_id": "Election" }
{ "text": "Election" }
"
}
}
但它不起作用。具体来说,它会抛出:
{
"data": {
"createTopics": null
},
"errors": [
{
"path": [
"createTopics"
],
"data": null,
"errorType": "MappingTemplate",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "Unexpected character ('i' (code 105)): was expecting comma to separate Object entries\n at [Source: (String)\"{\n \"version\": \"2017-02-28\",\n \"operation\": \"POST\",\n \"path\": \"/topic-en/doc/_bulk\",\n \"params\": {\n \"headers\" : { \"Content-Type\" : \"application/x-ndjson\" },\n \"body\": \"{ \"index\": { \"_id\": \"CODID\" } }\n{ \"text\": \"CODID\", \"suggest\": { \"input\": \"CODID\" } }\n{ \"index\": { \"_id\": \"Election\" } }\n{ \"text\": \"Election\", \"suggest\": { \"input\": \"Election\" } }\n\"\n }\n}\n\"; line: 7, column: 18]"
}
]
}
有什么想法吗?
【问题讨论】:
标签: elasticsearch aws-appsync resolver vtl