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.
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 .
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With