Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 256
aravchr Avatar asked Jan 16 '15 10:01

aravchr


People also ask

How do I access Elasticsearch logs?

To access logs, run docker logs . For Debian installations, Elasticsearch writes logs to /var/log/elasticsearch . For RPM installations, Elasticsearch writes logs to /var/log/elasticsearch .

What is CTX in Elasticsearch?

ctx is a special variable that allows you to access the source of the object that you want to update. The ctx. _source is a writable version of the source . NOTE: You can modify this document in the script and the modified source will be persisted as the new version of the document.

How do I push logs into Elasticsearch?

To send logs to Sematext Logs (or your own Elasticsearch cluster) via HTTP, you can use the elasticsearch output. You'll need to specify that you want the HTTP protocol, the host and port of an Elasticsearch server. For Sematext Logs, those would be logsene-receiver.sematext.com and port 443.


1 Answers

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.

like image 152
Vineeth Mohan Avatar answered Oct 29 '22 15:10

Vineeth Mohan