AWS API网关和弹性搜索获取查询 [英] AWS API gateway and elastic search get query
问题描述
我需要使用http连接直接从api网关调用弹性搜索引擎.
I need to call elastic search engine directly from api gateway using http connection eg.
https:////__ doc/_search?pretty& filter_path = hits.hits._source
https:////_doc/_search?pretty&filter_path=hits.hits._source
我在弹性搜索引擎中有n个订单,我想使用get查询获得订单,但是我只希望发布json数组,并且不希望响应中包含任何其他信息.我该怎么办?
i have n number of orders in elastic search engine which i want to get using get query ,but i want only array of json i posted and dont want any other information in the response.how can i do that ?
例如
这就是我得到的:
{
"hits" : {
"hits" : [
{
"_index" : "gpss_orders",
"_type" : "_doc",
"_id" : "4867254",
"_score" : 1.0,
"_source" : {
"orderId" : 4867254,
"loadId" : 18214,
"orderTypeId" : 1
}
]
}
}
但是我想要回复这样的内容:
But i would want response something like this :
[ {
"orderId" : 4867254,
"loadId" : 18214,
"orderTypeId" : 1
}]
我需要更改api网关方法响应吗?
do i need to change in api gateway method response?
我更改了api网关方法响应模板并获得了预期的结果
i changed the api gateway method response template and got the expected out
#set($esOutput = $input.path('$.hits.hits'))
#set($orders = [])
#foreach( $elem in $esOutput )
#set($order = $elem["_source"])
#set($response = $orders.add($order) )
#end
$orders
但是现在我面临的问题是,尽管弹性搜索引擎的响应是正确的json,但方法集成模板更新后的响应变成这样,没有任何花括号:
but now the problem i am facing is that though response from elastic search engine is the proper json,response after method integration template update become like this without any braces :
[{orderId=4867254, loadId=18214, orderTypeId=1, orderTypeName=Fuel}]
弹性搜索的响应:
"took" : 1,
"hits" : {
"hits" : [
{
"_id" : "4867254",
"_score" : 1.0,
"_source" : {
"orderId" : 4867254,
"loadId" : 18214,
"orderTypeId" : 1,
推荐答案
没有一种方法可以通过Elasticsearch调整返回对象的形状.根据访问此数据的方式,您可以将自己的服务器端代码作为代理进行查询,并删除多余的信息,然后再将其返回给客户端.好处是,您可以使用代理根据权限,缓存或速率限制等因素来决定返回哪些信息.
There isn't a way to shape the return object from elasticsearch. Depending on how you access this data, you could have your own server-side code as a proxy make the query and remove extraneous information before returning it to the clients. A bonus is you can use the proxy to decide what information to return depending on factors such as permissions, caching or rate-limiting, etc.
这篇关于AWS API网关和弹性搜索获取查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!