记录elastic4s客户端

时间:2017-01-24 12:27:15

标签: scala elasticsearch elastic4s

看这个例子

client.execute{search in "places"->"cities" query "paris" start 5 limit 10}

是否可以选择挂钩登录到client.execute以记录客户端所做的所有操作(索引,搜索等)?

我看到了这个answer,但我不想做类似的事情:

val req = search in "index" / "type" query "kate bush"
logger.debug(s"Search request ${req.show}")

我希望客户端根据日志记录级别记录所有内容

1 个答案:

答案 0 :(得分:0)

您可以使用覆盖执行功能

来定义自己的ElasticClient
app.post('/upload', function (req, res) {
  //var dirname = require('path').dirname(__dirname);
  //var dirname1 = require('path').dirname(dirname);
  var filename = req.files[0].filename;
  var path = req.files[0].path;
  var type = req.files[0].mimetype;
  var options = {
    contentType: type,
    metadata: { fileName: filename }
  }
  blobSvc.createBlockBlobFromLocalFile(containerName, filename, path, options, function (error, result, response) {
    if (error != null) {
      console.log('Azure Full Error: ', error)
    } else {
      console.log(result);
      console.log(response);
      var user = new User();
      user.name = req.body.name;
      user.picture = 'https://yourblob.blob.core.windows.net/profile/' + result.name;
      user.save(function (err) {
        if (err) {
          return res.json(err.message);
        }
        else {
          return res.json({ User: user });
        }
      });
    }
  });
});

查看TcpClient以获取参考https://github.com/sksamuel/elastic4s/blob/9a4074b6ff5616b648801352b4c3629cd0fc9020/elastic4s-tcp/src/main/scala/com/sksamuel/elastic4s/TcpClient.scala