Access Logger from Elasticsearch script

I use scripts aggressively for scoring and aggregation. One thing I cannot understand is to emit logs from a script. I tried console.log, but then it did not work. Please let me know how I can emit logs from my groovy script.

+7
aggregation elasticsearch
source share
1 answer

This can be done by accessing the global Elasticsearch log instance. The groovy example is shown below. You should also do something similar for javascript and other scripting languages.

import org.elasticsearch.common.logging.*; ESLogger logger=ESLoggerFactory.getLogger('myscript'); logger.info('This is a log message'); 

So, when you do the aggregation of terms, 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 people from Elasticsearch gave good documentation on this.

LINK - https://github.com/elasticsearch/elasticsearch/issues/9068

I also gave some examples here .

+9
source share

All Articles