Access logger from Elasticsearch script

谁都会走 提交于 2019-11-28 00:30:53

问题


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.


回答1:


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;"
          }
      }
}

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.



来源:https://stackoverflow.com/questions/27981832/access-logger-from-elasticsearch-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!