0

i have my data residing on an SSH server and i want to inquire and retrieve the data via HTTP POST and GET requests. i have been trying to do that using the simple url's http://127.0.0.1:9200/_search? but it gives me an empty response. What is the correct way to send requests over ssh server through http? my http post function looks something like this:

function spatialsearch(coordinates_selected) {
  var coords = coordinates_selected.geometry.coordinates;
  console.log('c',JSON.stringify(coordinates_selected.geometry.coordinates));
  var _url = 'http://127.0.0.1:9200/_search?';

  var b = {
    "query": {
      "bool": {
        "must": {
          "match_all": {}
        },
        "filter": {
          "geo_shape": {
            "metadata.o2r.spatial.geometry": {
              "shape": {
                "type": "polygon",
                "coordinates":
                coords

                /* [
                //     [-22.0, 76.0],
                //     [-27.0, 65.0],
                //     [-57.0, 65.0],
                //     [-59.0, 76.0],
                //     [-22.0, 76.0]
                ]*/

              },
              "relation": "within"
            }}}}}
  };

  console.log(b,'http sending request');
  return $http.post(_url,b);
}

i tried SSH tunneling using ssh -L9201:sshserver:9200 r_chau02@sshserver but i am still not getting any response.

update i updated the port in my code to 9201 but still the result was same. The error in console is net::ERR_EMPTY_RESPONSE while the terminal generates channel 3: open failed: connect failed: Connection refused.

  • This doesn't really sounds like it makes sense. SSH is SSH and HTTP is HTTP. I don't really get what you're trying to do. Do you have a webserver that would be able to answer the HTTP request? – Seth May 17 '17 at 8:35
  • @Seth i have webserver on which elasticsearch instance and all my data resides and which i access through SSH and now i have created an HTTP query to fetch that data but it's returning a bad request (400). The server is just a normal server. hope this clears out confusion – Rehan May 17 '17 at 8:45
0

You are looking in the right direction, with a minor error. The HTTP request and forwarding port don't match (9200 and 9201).

You can either update your code to query on port 9201, or change the ssh tunnel to:

ssh -L9201:127.0.0.1:9200 r_chau02@sshserver

This will make ES available on localhost:9200 (assuming tunneling is enabled on the server, and ES is listening on the sshserver address).

  • i tried changing the port in code. it does not works. i have updated the question with some errors – Rehan May 17 '17 at 10:41
  • It seems your ES server is not listening on sshserver:9200. Is it bound to a specific IP? – mtak May 17 '17 at 12:10
  • i am just using the default configurations of ES and i think that by deafult it is bound to "127.0.0.1" although i am not sure. how should i make it listen? – Rehan May 17 '17 at 12:16
  • You don't have to. I updated my answer with an SSH tunnel that forwards from localhost:9201 on your client to 127.0.0.1:9200 on the remote host. – mtak May 18 '17 at 8:44
  • that worked fine but it would be great if i could access it without ssh tunnelling. i treid by changing me code to http:\\sshserver:9200. but i am recieving this error net::ERR_CONNECTION_REFUSED. – Rehan May 18 '17 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.