简体   繁体   中英

Can we install plugins on an independent Node of Elasticsearch for testing purposes?

I am using a NodeBuilder for creation and testing of an index. This runs perfectly fine but I also have to use the mapper-attachment plugin as I am indexing PDFs as well. But as soon as I try indexing a PDF document in that node's index, I get org.elasticsearch.index.mapper.MapperParsingException: No handler for type [attachment] declared on field [pdf_text] . This is only because this plugin is not installed.

I checked NodeInfo of the temporary node I created it I got "plugins": [] ie no plugins are installed there. Actually it should be:

"plugins" : [ {
        "name" : "marvel",
        "version" : "1.3.1",
        "description" : "Elasticsearch Management & Monitoring",
        "url" : "/_plugin/marvel/",
        "jvm" : true,
        "site" : true
      }, {
        "name" : "mapper-attachments",
        "version" : "2.6.0",
        "description" : "Adds the attachment type allowing to parse difference attachment formats",
        "jvm" : true,
        "site" : false
      } ]

Any way I could do that?

I managed to do what you want with the help of this forum post : https://discuss.elastic.co/t/add-plugins-from-classpath-in-embedded-elasticsearch-client-node/36269/2

It consists in extending the Node class to allow to declare the list of plugins :

import org.elasticsearch.Version;
import org.elasticsearch.env.Environment;
import org.elasticsearch.node.Node;
import org.elasticsearch.plugins.Plugin;

import java.util.Collection;

/**
 * Node allowing to declare a list of plugins
 */
public class EmbeddedNode extends Node {

  private Version version;
  private Collection<Class<? extends Plugin>> plugins;

  public EmbeddedNode(Environment environment, Version version, Collection<Class<? extends Plugin>> classpathPlugins) {
    super(environment, version, classpathPlugins);
    this.version = version;
    this.plugins = classpathPlugins;
  }

  public Collection<Class<? extends Plugin>> getPlugins() {
    return plugins;
  }

  public Version getVersion() {
    return version;
  }
}

and then start the node with the list of plugins (here mapper-attachment and delete-by-query plugins) :

Environment environment = new Environment(Settings.settingsBuilder().build());
Collection plugins = new ArrayList<>();
Collections.<Class<? extends Plugin>>addAll(plugins, MapperAttachmentsPlugin.class, DeleteByQueryPlugin.class);
node = new EmbeddedNode(environment, Version.CURRENT, plugins);
node.start();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM