Kno*_*ob1 1 node.js elasticsearch
我有一个弹性搜索服务器,我想查询,但在向用户显示结果之前,我想过滤结果(在数据库中查找用户的权限等)
所以我想我写了一个代理服务器,它收到JSON POST搜索请求并将其重定向到Elasticsearch Server.现在将结果的响应发送到"过滤器服务器".此服务器在数据库中查找收到的json数据,并删除不允许用户查看的结果.此过滤的内容应呈现给用户.
好的 - 这就是我所做的:
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)
Run Code Online (Sandbox Code Playgroud)
这是代理服务器,但没有过滤实例过滤结果的部分.我尝试了很多东西,但是无法让它按照我想要的方式工作.我希望有人可以帮助我!
这就是你需要的:
https://github.com/lukas-vlcek/node.es
这是一个简单但有用的elasticsearch代理,基于node.js构建,代理允许通过定义两个函数来拦截和修改请求和响应:
var preRequest = function(request) {};
var postRequest = function(request, response, responseData){};
var proxyServer = proxyFactory.getProxy(preRequest, postRequest);
proxyServer.start();
Run Code Online (Sandbox Code Playgroud)
看看这个例子:
https://github.com/lukas-vlcek/node.es/blob/master/proxy/proxy-example.js
| 归档时间: |
|
| 查看次数: |
1785 次 |
| 最近记录: |