Hello World ES Plugin

My goal is to test the invocation of some in-house software from within an ES plugin. My approach was to make a simple, Hello World style plugin that would print to the ES log/console. If I can see my log output, then I know when my code path is being triggered. This way, I can hook in my desired invocation, and know when it is being invoked.

Using the examples from the source code, I was able to make a bare-bones NativeScriptPlugin (I prefer this type of plugin for other reasons). It compiles, and the plugin zip installs without error, but I cannot seem to invoke it. That is my problem. I think the root problem is my lack of understanding of the plugin system and ES, but I am not really seeing any docs with any detail. I only see the docs on "Help for plugin authors", but that is minimal.

Here is the curl I use to try and invoke my plugin.

curl -XPOST 'localhost:9200/_search' -d '
{
  "query": {
    "script": {
      "script": {
                "name": "invoke_schema",
                "lang" : "native"
      }
    }
  }
}
'

The name of the script is correct. I am using ES 5.5.2.

I've tried debugging into the plugin, which works, but doesn't enter the run() method of the plugin. I have the run() method doing a System.out.println, hoping to see something in the ES console output. Sadly, none of this worked as I expected.

Any ideas? Please and thank you.

Do you have any documents in your index? A search script is run for each document matching the query (in this case, all documents in the index). Additionally, printing to stdout will be a black hole, depending on how you started elasticsearch, and it definitely will not go the the elasticsearch log. You need to construct a Logger for your class and log at a level that is visible (by default, INFO and above).

Thanks for your help. I achieved my goal but with the following findings.

The script I ended up using to invoke the plugin was:

curl -XPOST 'localhost:9200/twitter/type/1/_update' -d '
{
  "query": {
    "scripted_upsert": true,
    "upsert" : {},
      "script": {
        "inline": "invoke_schema",
        "lang" : "native"
      }
  }
}
'
  • I did not need any documents for this type of invocation.
  • Because I launched a local ES from bash, System.out.println worked fine for my needs.

Thank you!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.