从 Elasticsearch 脚本访问记录器 [英] Access logger from Elasticsearch script

查看:23
本文介绍了从 Elasticsearch 脚本访问记录器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我积极使用脚本进行评分和聚合.我无法弄清楚的一件事是如何从脚本中发出日志.我试过 console.log ,但后来没有成功.请让我知道,我如何从我的 groovy 脚本中发出日志.

I use the scripts aggressively for scoring and aggregation. One thing i cant figure out is how to emit logs from the script. I tried console.log , but then it didnt work out. Kindly let me know , how i can emit logs from my groovy script.

推荐答案

这可以通过访问全局 Elasticsearch 记录器实例来完成.下面给出了它的常规示例您也应该能够对 javascript 和其他脚本语言执行类似的操作.

This can be done by accessing global Elasticsearch logger instance. Its groovy example is given below You should be able to do something similar for javascript and other scripting languages too.

import  org.elasticsearch.common.logging.*; 
ESLogger logger=ESLoggerFactory.getLogger('myscript'); 
logger.info('This is a log message'); 

因此,当您进行术语聚合时,您可以执行以下操作 -

So when you do a terms aggregation , you can do something like below -

  "aggregations": {
      "debug":{
          "terms":{
              "script":"import  org.elasticsearch.common.logging.*; ESLogger logger=ESLoggerFactory.getLogger('myscript'); logger.info('This is a log message'); return doc['myField'].value;"
          }
      }
}

一些来自 Elasticsearch 的好人针对某个问题提供了很好的文档.

Some good folks from Elasticsearch has given a good documentation on it against a issue.

LINK - https://github.com/elasticsearch/elasticsearch/issues/9068

我还在这里给出了一些例子.

I have also given some examples here.

这篇关于从 Elasticsearch 脚本访问记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆