Query index from within an AnalysisProvider?


Here is the context of my question: Synonym graph token filter backed by Elastic index

I am writing a custom AnalysisPlugin to generate a list of synonyms from an Elastic index instead of using a static file.

A naive approach would be to use the REST client during its instantiation and point it to localhost then query in the usual way to populate the synonym map but I was wondering whether there would be a more efficient / cleaner way of doing e.g. I have a TokenFilterFactory with the following constructor (IndexSettings indexSettings, Environment env, String name, Settings settings), can I retrieve the port number from there? Is there a better way of doing?


Answering my own question: yes, it is possible to retrieve the host and port of Elasticsearch from the settings of the Environment object

this.port = env.settings().getAsInt(http.port, 9200);
this.host = env.settings().get(network.host,localhost);

this way my plugin doesn't need the users to set the values themselves, which is great.

Using this info with the Java client within the plugin code, I am getting

"caused_by" : {
          "type" : "access_control_exception",
          "reason" : "access denied (\"java.net.SocketPermission\" \"\" \"connect,resolve\")"

when querying the index with Elastic running as a docker container.

Is there a way I can either

  1. configure ES to accept incoming traffic from a plugin it is runs?
  2. use Java security permissions in the plugin?

Going back to my original question, is there an alternative to using the Java Ciient within the plugin to query Elastic?

Any help and pointers would be greatly appreciated

Changing the security permissions for the plugin did the trick.

Creating a file with

grant {
  permission java.net.SocketPermission "localhost", "accept,connect,listen,resolve";
  permission java.net.SocketPermission "", "accept,connect,listen,resolve";

allows the code in my plugin to connect to ES

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