1 year ago
#388958

JDBennett
JsonPath mapping not working AWS Integration Response Api Gateway
I have an AWS Api Gateway set-up with an integration to an HTTP endpoint (specifically an AWS OpenSearch instance).
I want to transform the response from a query result from OpenSearch - effectively remove all unnecessary properties.
The response from a search from OpenSearch looks like this:
{
"took": 14,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": 1,
"hits": [
{
"_index": "drugs",
"_type": "_doc",
"_id": "5443",
"_score": 1,
"_source": {
"name": "adderall",
"med_id": "5443"
}
},
{
"_index": "drugs",
"_type": "_doc",
"_id": "5444",
"_score": 1,
"_source": {
"name": "adderall xr",
"med_id": "5444"
}
}
]
}
}
I want to transform that response with an Integration Mapping - returning only the
hits.hits[]._source.name
i.e.
{
"adderall"
"adderall xr"
}
I have a model defined in api gateway:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "SearchResultModel",
"type": "object",
"properties": {
"hits": {
"type": "object",
"properties": {
"hits": {
"type": "array",
"hits": {
"$ref": "#/definitions/hit"
}
}
}
}
},
"definitions": {
"hit": {
"type": "object",
"properties": {
"_index": {
"type": "string"
},
"_type": {
"type": "string"
},
"_id": {
"type": "string"
},
"_score": {
"type": "integer"
},
"_source": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"med_id": {
"type": "string"
}
}
}
}
}
}
}
and the mapping template defined as:
#set($inputRoot = $input.path('$.hits'))
{
#foreach($elem in $inputRoot.hits)
"$elem._source.name"
#if($foreach.hasNext),#end
#end
}
When I issue the request via post man - I am getting this result:
amazon-web-services
aws-api-gateway
transformation
0 Answers
Your Answer