org.elasticsearch.common.settings.SettingsModule Java Examples

The following examples show how to use org.elasticsearch.common.settings.SettingsModule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IkESPluginTest.java    From es-ik with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultsIcuAnalysis() {
    Index index = new Index("test");

    Settings settings = ImmutableSettings.settingsBuilder()
            .put("path.home", "none")
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .build();

    Injector parentInjector = new ModulesBuilder().add(new SettingsModule(ImmutableSettings.EMPTY), new EnvironmentModule(new Environment(settings)), new IndicesAnalysisModule()).createInjector();
    Injector injector = new ModulesBuilder().add(
            new IndexSettingsModule(index, settings),
            new IndexNameModule(index),
            new AnalysisModule(ImmutableSettings.EMPTY, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new IKAnalysisBinderProcessor()))
            .createChildInjector(parentInjector);

    AnalysisService analysisService = injector.getInstance(AnalysisService.class);

    TokenizerFactory tokenizerFactory = analysisService.tokenizer("ik_tokenizer");
    MatcherAssert.assertThat(tokenizerFactory, instanceOf(IKTokenizerFactory.class));


}
 
Example #2
Source File: HanLpAnalysisTests.java    From elasticsearch-analysis-hanlp with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultsIcuAnalysis() {
    Index index = new Index("test");
    Settings settings = settingsBuilder()
        .put("path.home", createTempDir())
        .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
        .build();
    Injector parentInjector = new ModulesBuilder().add(new SettingsModule(EMPTY_SETTINGS), new EnvironmentModule(new Environment(settings))).createInjector();
    Injector injector = new ModulesBuilder().add(
        new IndexSettingsModule(index, settings),
        new IndexNameModule(index),
        new AnalysisModule(EMPTY_SETTINGS, parentInjector.getInstance(IndicesAnalysisService.class)).addProcessor(new HanLpAnalysisBinderProcessor()))
                                            .createChildInjector(parentInjector);

    AnalysisService analysisService = injector.getInstance(AnalysisService.class);

    TokenizerFactory tokenizerFactory = analysisService.tokenizer("smartcn_tokenizer");
    MatcherAssert.assertThat(tokenizerFactory, instanceOf(HanLpTokenizerTokenizerFactory.class));
}
 
Example #3
Source File: MapperTestUtils.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static AnalysisService newAnalysisService(Settings indexSettings) {
    Injector parentInjector = new ModulesBuilder().add(new SettingsModule(indexSettings), new EnvironmentModule(new Environment(indexSettings))).createInjector();
    Index index = new Index("test");
    Injector injector = new ModulesBuilder().add(
        new IndexSettingsModule(index, indexSettings),
        new IndexNameModule(index),
        new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class))).createChildInjector(parentInjector);

    return injector.getInstance(AnalysisService.class);
}
 
Example #4
Source File: MapperTestUtils.java    From elasticsearch-analysis-baseform with Apache License 2.0 5 votes vote down vote up
public static AnalysisService newAnalysisService(Settings indexSettings) {
    Injector parentInjector = new ModulesBuilder().add(new SettingsModule(indexSettings),
            new EnvironmentModule(new Environment(indexSettings))).createInjector();
    Index index = new Index("test");
    Injector injector = new ModulesBuilder().add(
            new IndexSettingsModule(index, indexSettings),
            new IndexNameModule(index),
            new AnalysisModule(indexSettings, parentInjector.getInstance(IndicesAnalysisService.class))).createChildInjector(parentInjector);

    return injector.getInstance(AnalysisService.class);
}
 
Example #5
Source File: MapperTestUtils.java    From elasticsearch-analysis-baseform with Apache License 2.0 5 votes vote down vote up
public static MapperService newMapperService(Settings settings, Client client) {
    Settings indexSettings = Settings.builder()
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put("path.home", System.getProperty("path.home"))
            .put("client.type", "node")
            .put(settings)
            .build();
    Index index = new Index("test");
    Injector parentInjector = new ModulesBuilder()
            .add(new SettingsModule(indexSettings),
            new EnvironmentModule(new Environment(indexSettings)))
            .createInjector();
    AnalysisModule analysisModule = new AnalysisModule(indexSettings,
            parentInjector.getInstance(IndicesAnalysisService.class));
    new AnalysisBaseformPlugin(settings).onModule(analysisModule);
    Injector injector = new ModulesBuilder().add(new IndexSettingsModule(index, indexSettings),
            new IndexNameModule(index),
            analysisModule)
            .createChildInjector(parentInjector);
    AnalysisService analysisService = injector.getInstance(AnalysisService.class);
    SimilarityLookupService similarityLookupService = new SimilarityLookupService(index, indexSettings);
    Map<String, Mapper.TypeParser> mappers = registerBuiltInMappers();
    Map<String, MetadataFieldMapper.TypeParser> metadataMappers = registerBuiltInMetadataMappers();
    MapperRegistry mapperRegistry = new MapperRegistry(mappers, metadataMappers);
    return new MapperService(new Index("test"),
            indexSettings,
            analysisService,
            similarityLookupService,
            null,
            mapperRegistry);
}
 
Example #6
Source File: TransportClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * Builds a new instance of the transport client.
 */
public TransportClient build() {
    Settings settings = InternalSettingsPreparer.prepareSettings(this.settings);
    settings = settingsBuilder()
            .put(NettyTransport.PING_SCHEDULE, "5s") // enable by default the transport schedule ping interval
            .put(settings)
            .put("network.server", false)
            .put("node.client", true)
            .put(CLIENT_TYPE_SETTING, CLIENT_TYPE)
            .build();

    PluginsService pluginsService = new PluginsService(settings, null, null, pluginClasses);
    this.settings = pluginsService.updatedSettings();

    Version version = Version.CURRENT;

    final ThreadPool threadPool = new ThreadPool(settings);
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();

    boolean success = false;
    try {
        ModulesBuilder modules = new ModulesBuilder();
        modules.add(new Version.Module(version));
        // plugin modules must be added here, before others or we can get crazy injection errors...
        for (Module pluginModule : pluginsService.nodeModules()) {
            modules.add(pluginModule);
        }
        modules.add(new PluginsModule(pluginsService));
        modules.add(new SettingsModule(this.settings));
        modules.add(new NetworkModule(namedWriteableRegistry));
        modules.add(new ClusterNameModule(this.settings));
        modules.add(new ThreadPoolModule(threadPool));
        modules.add(new TransportModule(this.settings, namedWriteableRegistry));
        modules.add(new SearchModule() {
            @Override
            protected void configure() {
                // noop
            }
        });
        modules.add(new ActionModule(true));
        modules.add(new ClientTransportModule());
        modules.add(new CircuitBreakerModule(this.settings));

        pluginsService.processModules(modules);

        Injector injector = modules.createInjector();
        final TransportService transportService = injector.getInstance(TransportService.class);
        transportService.start();
        transportService.acceptIncomingRequests();

        TransportClient transportClient = new TransportClient(injector);
        success = true;
        return transportClient;
    } finally {
        if (!success) {
            ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS);
        }
    }
}
 
Example #7
Source File: TransportClient.java    From elasticsearch-helper with Apache License 2.0 4 votes vote down vote up
public TransportClient build() {
    Settings settings = InternalSettingsPreparer.prepareSettings(this.settings);
    settings = settingsBuilder()
            .put("transport.ping.schedule", this.settings.get("ping.interval", "30s"))
            .put(settings)
            .put("network.server", false)
            .put("node.client", true)
            .put(CLIENT_TYPE_SETTING, CLIENT_TYPE)
            .build();
    PluginsService pluginsService = new PluginsService(settings, null, null, pluginClasses);
    this.settings = pluginsService.updatedSettings();
    Version version = Version.CURRENT;
    final ThreadPool threadPool = new ThreadPool(settings);
    final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();

    boolean success = false;
    try {
        ModulesBuilder modules = new ModulesBuilder();
        modules.add(new Version.Module(version));
        // plugin modules must be added here, before others or we can get crazy injection errors...
        for (Module pluginModule : pluginsService.nodeModules()) {
            modules.add(pluginModule);
        }
        modules.add(new PluginsModule(pluginsService));
        modules.add(new SettingsModule(this.settings));
        modules.add(new NetworkModule(namedWriteableRegistry));
        modules.add(new ClusterNameModule(this.settings));
        modules.add(new ThreadPoolModule(threadPool));
        modules.add(new TransportModule(this.settings, namedWriteableRegistry));
        modules.add(new SearchModule() {
            @Override
            protected void configure() {
                // noop
            }
        });
        modules.add(new ActionModule(true));
        modules.add(new ClientTransportModule(hostFailedListener));
        modules.add(new CircuitBreakerModule(this.settings));
        pluginsService.processModules(modules);
        Injector injector = modules.createInjector();
        injector.getInstance(TransportService.class).start();
        TransportClient transportClient = new TransportClient(injector);
        success = true;
        return transportClient;
    } finally {
        if (!success) {
            ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS);
        }
    }
}