1

I am trying to exclude fields from response that is returned from elasticsearch using postman pre-request script but looks like exclude is not working as expected. Below is my pre-request script -

pm.sendRequest({
        url: 'https://' + pm.globals.get("creds") + pm.globals.get("server") + ':9200/' + pm.globals.get("details") + '/_read',
        method: 'POST',
        header: {
            'content-type': 'application/json'
        },
        body: {
            mode: 'raw',
            raw: JSON.stringify({

    "query": {
    "bool": {
      "must": [
        {
          "match": {
            "id":pm.environment.get("id")
          }
        }
      ]
    }
  },
  "_source": {
          "exclude" : ["demographic.*"]
     }
}
            )
        }
    }
);

I have already tested this query in elastic search and it is working as expected. I would appreciate any help

Jon Abraham
  • 851
  • 3
  • 14
  • 27
  • Hey Jon, can you provide some more context please. This looks like a request inside and main request, where are you hoping to see the output of this? – Danny Dainton Apr 07 '20 at 07:23
  • @DannyDainton i am hoping to see this output in postman i.e. response body. So the postman pre-request script is used prior to the request that is being sent to API. In this case i am trying to send a pre-request to elastic-search with query and then i want to perform assertion over the response but my concern is that this query is not working in postman as expected. It should exclude the demographics array from the response but it is not – Jon Abraham Apr 07 '20 at 13:07
  • Actually never mind i was able to check in console that my query is working as expected. – Jon Abraham Apr 07 '20 at 13:17
  • 1
    You're only ever going to see the output from a `.sendRequest` in the Postman Console. Unless the request is the main request in the builder, you're not going to see that in the response body section. – Danny Dainton Apr 07 '20 at 13:59
  • yes thank you for clarifying this to me. I should have known that pre-requests are meant for postman console not for API response – Jon Abraham Apr 07 '20 at 14:08

0 Answers0