Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

aggregation - Access logger from Elasticsearch script

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...