I have an elasticsearch Server which I would like to query, but before showing the result to the User I want to filter the results (looking up the rights for the User in a Database etc.)
So I thought I write a proxy Server which recieves JSON POST Search request and redirect this to the Elasticsearch Server. The response with the results now be sent to the "filter server". This Server looks the recieved json-data up in a Database and removes the results which the User isn't allowed to see. This filtered content should be presented to the user.
Ok - this is what i've done:
var proxy = http.createServer(function (req, res){
if(req.method == 'OPTIONS'){
res.writeHead(200, {'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json; charset=UTF-8'});
res.end();
}
if(req.method == 'POST'){
var searchOptions = {
host: '10.0.10.1',
port: 9200,
method: 'POST',
path: '/ltg_5096/_search'
}
var searchRequest = http.request(searchOptions, function(searchResponse){
// this is the Request to the Elasticsearch Server...
var filterOptions = {
host: '127.0.0.1',
port: 8080,
method: 'POST',
path: '/',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}
var filterRequest = http.request(filterOptions, function(filterResponse){
// ?! This should be the request to the filter Server
})
searchResponse.pipe(res)
res.writeHead(200, {'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json; charset=UTF-8'})
})
req.pipe(searchRequest)
}
})
proxy.listen(9000)
This is the proxy Server but without the part where the results are filtered by the filtering instance. I tried lots of things, but couldn't get it to work as I want it to. I hope somebody can help me with this!