从Elasticsearch脚本访问记录器 [英] Access logger from Elasticsearch script
问题描述
我用脚本积极地进行评分和聚合。我无法想像的是如何从脚本中发出日志。我试过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记录器实例来完成。
它的groovy示例在下面给出
你应该能够为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
LINK - https://github.com/elasticsearch/elasticsearch/issues/9068
我还给了一些例子这里。
这篇关于从Elasticsearch脚本访问记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!