Could not install Analysis Plugin that I created

I have created a new analysis plugin with mvn, but installation bin/elasticsearch-plugin install failed.

Env

  • CentOS 7
  • elasticsearch 7.2.0
  • java 1.8

Files

  • pom.xml
  • src/main/assemblies/plugin.xml
  • src/main/resources/plugin-descriptor.properties
  • src/main/java/hoge/AnalysisHogePlugin.java
  • src/main/java/hoge/HogeTokenizerFactory.java
  • src/main/java/hoge/HogeTokenizer.java

Contents of the plugin

For a minimal example, I created an analysis plugin that does nothing:

  • AnalysisHogePlugin:
package hoge;

import org.apache.lucene.analysis.Analyzer;
import org.elasticsearch.index.analysis.TokenizerFactory;
import org.elasticsearch.indices.analysis.AnalysisModule.AnalysisProvider;
import org.elasticsearch.plugins.AnalysisPlugin;
import org.elasticsearch.plugins.Plugin;

import java.util.Map;

import static java.util.Collections.singletonMap;

import hoge.HogeTokenizerFactory;

public class AnalysisHogePlugin extends Plugin implements AnalysisPlugin {
  @Override
  public Map<String, AnalysisProvider<TokenizerFactory>> getTokenizers() {
    return singletonMap("hoge_tokenizer", HogeTokenizerFactory::new);
  }
}

  • HogeTokenizer:
package hoge;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;

import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.apache.lucene.analysis.tokenattributes.PositionLengthAttribute;
import org.apache.lucene.analysis.util.RollingCharBuffer;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.AttributeFactory;

public final class HogeTokenizer extends Tokenizer {

  private final RollingCharBuffer buffer = new RollingCharBuffer();

  private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
  private final OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
  private final PositionIncrementAttribute posIncAtt = addAttribute(PositionIncrementAttribute.class);
  private final PositionLengthAttribute posLengthAtt = addAttribute(PositionLengthAttribute.class);

  public HogeTokenizer() {
  }

  public HogeTokenizer(AttributeFactory factory) {
    super(factory);
  }

  @Override
  public void close() throws IOException {
    super.close();
  }

  @Override
  public void reset() throws IOException {
    super.reset();
  }

  @Override
  public void end() throws IOException {
    super.end();
  }

  @Override
  public boolean incrementToken() throws IOException {
    return false;
  }
}

  • HogeTokenizerFactory:
package hoge;

import org.apache.lucene.analysis.Tokenizer;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.analysis.AbstractTokenizerFactory;

import hoge.HogeTokenizer;

public class HogeTokenizerFactory extends AbstractTokenizerFactory {

  public HogeTokenizerFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) {
    super(indexSettings, settings);
  }

  @Override
  public Tokenizer create() {
    return new HogeTokenizer();
  }
}

  • plugin-descriptor.properties:
description=Hoge analyzer
version=0.1.0
name=analysis-hoge
classname=hoge.AnalysisHogePlugin
java.version=1.8
elasticsearch.version=7.2.0
extended.plugins=
has.native.controller=false

Then, I ran mvn package and got a file analysis-hoge-0.1.0.zip, which contains

  • analysis-hoge-0.1.0.jar,
  • plugin-descriptor.properties.

Finally, when I ran bin/elasticsearch-plugin install file:///path/to/analysis-hoge-0.1.0.zip in the root directory of Elasticsearch-7.2.0, I got an error like:

$ bin/elasticsearch-plugin install file:///home/username/develop/analysis-hoge-0.1.0.zip
-> Downloading file:///home/username/develop/analysis-hoge-0.1.0.zip
[=================================================] 100%
Exception in thread "main" java.nio.file.NoSuchFileException: /home/username/develop/elasticsearch-7.2.0/plugins/.installing-4338817505847375416/plugin-descriptor.properties
	at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
	at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
	at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219)
	at java.base/java.nio.file.Files.newByteChannel(Files.java:373)
	at java.base/java.nio.file.Files.newByteChannel(Files.java:424)
	at java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420)
	at java.base/java.nio.file.Files.newInputStream(Files.java:158)
	at org.elasticsearch.plugins.PluginInfo.readFromProperties(PluginInfo.java:156)
	at org.elasticsearch.plugins.InstallPluginCommand.loadPluginInfo(InstallPluginCommand.java:714)
	at org.elasticsearch.plugins.InstallPluginCommand.installPlugin(InstallPluginCommand.java:793)
	at org.elasticsearch.plugins.InstallPluginCommand.install(InstallPluginCommand.java:776)
	at org.elasticsearch.plugins.InstallPluginCommand.execute(InstallPluginCommand.java:231)
	at org.elasticsearch.plugins.InstallPluginCommand.execute(InstallPluginCommand.java:216)
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124)
	at org.elasticsearch.cli.MultiCommand.execute(MultiCommand.java:77)
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124)
	at org.elasticsearch.cli.Command.main(Command.java:90)
	at org.elasticsearch.plugins.PluginCli.main(PluginCli.java:47)

What is wrong? I found little information about creating Elasticsearch plugins on Google search, so I have no idea how I can fix it.

Please tell me why such an error occurs and how to fix it.

from a high level view this looks ok. Is there any chance you can create a github repo, so one can locally reproduce this?

I only use the gradle and the esplugin plugin, which simplifies building plugins a lot, thus my mvn experience is close to zero.

--Alex

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