0
votes

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

1 Answers

0
votes

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.