IndexQueryParserModule queryParserModule = new IndexQueryParserModule(settings);
queryParserModule.addQueryParser("my", PluginJsonQueryParser.class);
queryParserModule.addFilterParser("my", PluginJsonFilterParser.class);
Index index = new Index("test");
Injector injector = new ModulesBuilder().add(
new CodecModule(settings),
new SettingsModule(settings),
new ThreadPoolModule(settings),
new IndicesQueriesModule(),
new ScriptModule(settings),
new IndexSettingsModule(index, settings),
new IndexCacheModule(settings),
new AnalysisModule(settings),
new IndexEngineModule(settings),
new SimilarityModule(settings),
queryParserModule,
new IndexNameModule(index),
new FunctionScoreModule(),
new AbstractModule() {
@Override
protected void configure() {
bind(ClusterService.class).toProvider(Providers.of((ClusterService) null));
bind(CircuitBreakerService.class).to(NoneCircuitBreakerService.class);
}
}
).createInjector();
IndexQueryParserService indexQueryParserService = injector.getInstance(IndexQueryParserService.class);
PluginJsonQueryParser myJsonQueryParser = (PluginJsonQueryParser) indexQueryParserService.queryParser("my");
assertThat(myJsonQueryParser.names()[0], equalTo("my"));
PluginJsonFilterParser myJsonFilterParser = (PluginJsonFilterParser) indexQueryParserService.filterParser("my");
assertThat(myJsonFilterParser.names()[0], equalTo("my"));
terminate(injector.getInstance(ThreadPool.class));
}