Custom TokenFilter Plugin Class Initialization and Parameter Validation

I have a custom TokenFilter I'm adding like this:

public class CompounderPlugin extends Plugin implements AnalysisPlugin {

 @Override
 public Map<String, AnalysisProvider<TokenFilterFactory>> getTokenFilters() {
	 Map<String, AnalysisProvider<TokenFilterFactory>> extra = new HashMap<>();
	 extra.put("compounder", CompounderTokenFilterFactory::new);
	 return extra;
 }
}

The issue I'm having is that in my CompounderTokenFilterFactory constructor, I'm validating parameters that should be provided in the settings. However, since the constructor is called both when registering the plugin regardless of whether we have a custom filter in settings, it is not possible to validate a parameter. I have to set a default value. I don't want to set a default, I want a parameter to be required.

This is exactly how https://github.com/elastic/elasticsearch/blob/5.2/core/src/main/java/org/elasticsearch/index/analysis/compound/AbstractCompoundWordTokenFilterFactory.java works. The factory constructor validates that word_list is present and throws if it is missing. If I replicate this code in my factory constructor, it throws upon creating any index -- even one without settings.

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