AWS API gateway and elastic search get query

喜欢而已 提交于 2020-02-29 08:03:49

问题


I need to call elastic search engine directly from api gateway using http connection eg.

https:////_doc/_search?pretty&filter_path=hits.hits._source

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 ?

eg.

this is what i am getting :

   {
      "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
              }]

do i need to change in api gateway method response?

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

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}]

response from elastic search :

"took" : 1,
  "hits" : {
    "hits" : [
      {
        "_id" : "4867254",
        "_score" : 1.0,
        "_source" : {
          "orderId" : 4867254,
          "loadId" : 18214,
          "orderTypeId" : 1,

回答1:


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.



来源:https://stackoverflow.com/questions/54825545/aws-api-gateway-and-elastic-search-get-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!