Java Code Examples for org.elasticsearch.common.settings.Settings#settingsBuilder()

The following examples show how to use org.elasticsearch.common.settings.Settings#settingsBuilder() . 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: PluginsService.java    From Elasticsearch with Apache License 2.0 7 votes vote down vote up
public Settings updatedSettings() {
    Map<String, String> foundSettings = new HashMap<>();
    final Settings.Builder builder = Settings.settingsBuilder();
    for (Tuple<PluginInfo, Plugin> plugin : plugins) {
        Settings settings = plugin.v2().additionalSettings();
        for (String setting : settings.getAsMap().keySet()) {
            String oldPlugin = foundSettings.put(setting, plugin.v1().getName());
            if (oldPlugin != null) {
                throw new IllegalArgumentException("Cannot have additional setting [" + setting + "] " +
                    "in plugin [" + plugin.v1().getName() + "], already added in plugin [" + oldPlugin + "]");
            }
        }
        builder.put(settings);
    }
    return builder.put(this.settings).build();
}
 
Example 2
Source File: InternalEsClient.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * インデックスを作成する.
 * @param index インデックス名
 * @param mappings マッピング情報
 * @return 非同期応答
 */
public ActionFuture<CreateIndexResponse> createIndex(String index, Map<String, JSONObject> mappings) {
    this.fireEvent(Event.creatingIndex, index);
    CreateIndexRequestBuilder cirb =
            new CreateIndexRequestBuilder(esTransportClient.admin().indices(), 
            		CreateIndexAction.INSTANCE, index);

    // cjkアナライザ設定
    Settings.Builder indexSettings = Settings.settingsBuilder();
    indexSettings.put("analysis.analyzer.default.type", "cjk");
    cirb.setSettings(indexSettings);

    if (mappings != null) {
        for (Map.Entry<String, JSONObject> ent : mappings.entrySet()) {
            cirb = cirb.addMapping(ent.getKey(), ent.getValue().toString());
        }
    }
    return cirb.execute();
}
 
Example 3
Source File: BaseClient.java    From elasticsearch-helper with Apache License 2.0 6 votes vote down vote up
public void updateIndexSetting(String index, String key, Object value) throws IOException {
    if (client() == null) {
        return;
    }
    if (index == null) {
        throw new IOException("no index name given");
    }
    if (key == null) {
        throw new IOException("no key given");
    }
    if (value == null) {
        throw new IOException("no value given");
    }
    Settings.Builder settingsBuilder = Settings.settingsBuilder();
    settingsBuilder.put(key, value.toString());
    UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(index)
            .settings(settingsBuilder);
    client().execute(UpdateSettingsAction.INSTANCE, updateSettingsRequest).actionGet();
}
 
Example 4
Source File: PluginLoader.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Settings additionalSettings() {
    Settings.Builder builder = Settings.settingsBuilder();
    for (Plugin plugin : plugins) {
        builder.put(plugin.additionalSettings());
    }
    return builder.build();
}
 
Example 5
Source File: SQLPlugin.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public Settings additionalSettings() {
    Settings.Builder settingsBuilder = Settings.settingsBuilder();

    // Set default analyzer
    settingsBuilder.put("index.analysis.analyzer.default.type", "standard");

    // Never allow implicit creation of an index, even on partitioned tables we are creating
    // partitions explicitly
    settingsBuilder.put("action.auto_create_index", true);

    return settingsBuilder.build();
}
 
Example 6
Source File: CrateComponentLoader.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Settings additionalSettings() {
    Settings.Builder builder = Settings.settingsBuilder();
    for (Plugin plugin : plugins) {
        builder.put(plugin.additionalSettings());
    }
    return builder.build();
}
 
Example 7
Source File: EsClientHelper.java    From jlogstash-input-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化并创建ES client
 *
 * @param config ES源配置
 * @return
 */
public static Client initClient(ElasticsearchSourceConfig config) throws UnknownHostException {
    // construct settings
    Settings.Builder builder = Settings.settingsBuilder();
    if (StringUtils.isNotEmpty(config.getCluster())) {
        builder.put("cluster.name", config.getCluster());
    }
    builder.put("client.transport.sniff", config.isSniff());
    Settings settings = builder.build();

    // build client
    TransportClient client = TransportClient.builder().settings(settings).build();

    // add node ip list
    List<String> hostList = config.getHosts();
    for (String host : hostList) {
        if (StringUtils.isNotEmpty(host)) {
            String[] hostAndPort = host.split(":");
            String hostAddr = hostAndPort[0];
            Integer port = 9300;
            if (hostAndPort.length > 1) {
                try {
                    port = Integer.valueOf(hostAndPort[1]);
                } catch (NumberFormatException e) {
                    logger.error(String.format("parse port '%s' error, use default port 9300", hostAndPort), e);
                }
            }
            client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostAddr), port));
        }
    }
    return client;
}
 
Example 8
Source File: IMAPImporterCl.java    From elasticsearch-imap with Apache License 2.0 5 votes vote down vote up
public static void start(Map<String, Object> settings, boolean embeddedMode) throws Exception {

        Settings.Builder builder = Settings.settingsBuilder();

        for(String key: settings.keySet()) {
            builder.put(key, String.valueOf(settings.get(key)));
        }
        
        if(embeddedMode) {
            try {
                FileUtils.forceDelete(new File("./data"));
            } catch (Exception e) {
                //ignore
            }
            builder.put("path.home",".");
            builder.put("node.local", true);
            builder.put("http.cors.enabled", true);
            builder.put("http.cors.allow-origin", "*");
            builder.put("cluster.name", "imap-embedded-"+System.currentTimeMillis());
            node = new PluginAwareNode(builder.build(), (Collection) Lists.newArrayList(MapperAttachmentsPlugin.class));
            node.start();
            client = node.client();
        }else
        {
            Settings eSettings = builder.build();
            client = new TransportClient.Builder().settings(eSettings).build();
            String[] hosts = eSettings.get("elasticsearch.hosts").split(",");
            
            for (int i = 0; i < hosts.length; i++) {
                String host = hosts[i];
                String hostOnly = host.split(":")[0];
                String portOnly = host.split(":")[1];
                System.out.println("Adding "+hostOnly+":"+portOnly);
                ((TransportClient)client).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostOnly), Integer.parseInt(portOnly)));
            }
        }
        imap = new IMAPImporter(settings, client);
        imap.start();
    }
 
Example 9
Source File: BaseClient.java    From elasticsearch-helper with Apache License 2.0 5 votes vote down vote up
public Settings settings() {
    if (settings != null) {
        return settings;
    }
    if (settingsBuilder == null) {
        settingsBuilder = Settings.settingsBuilder();
    }
    return settingsBuilder.build();
}
 
Example 10
Source File: BaseTransportClient.java    From elasticsearch-helper with Apache License 2.0 5 votes vote down vote up
protected Settings findSettings() {
    Settings.Builder settingsBuilder = Settings.settingsBuilder();
    settingsBuilder.put("host", "localhost");
    try {
        String hostname = NetworkUtils.getLocalAddress().getHostName();
        logger.debug("the hostname is {}", hostname);
        settingsBuilder.put("host", hostname)
                .put("port", 9300);
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
    }
    return settingsBuilder.build();
}
 
Example 11
Source File: BaseClient.java    From elasticsearch-helper with Apache License 2.0 4 votes vote down vote up
public void resetSettings() {
    settingsBuilder = Settings.settingsBuilder();
    settings = null;
    mappings = new HashMap<>();
}
 
Example 12
Source File: BaseClient.java    From elasticsearch-helper with Apache License 2.0 4 votes vote down vote up
public void setting(String key, String value) {
    if (settingsBuilder == null) {
        settingsBuilder = Settings.settingsBuilder();
    }
    settingsBuilder.put(key, value);
}
 
Example 13
Source File: BaseClient.java    From elasticsearch-helper with Apache License 2.0 4 votes vote down vote up
public void setting(String key, Boolean value) {
    if (settingsBuilder == null) {
        settingsBuilder = Settings.settingsBuilder();
    }
    settingsBuilder.put(key, value);
}
 
Example 14
Source File: BaseClient.java    From elasticsearch-helper with Apache License 2.0 4 votes vote down vote up
public void setting(String key, Integer value) {
    if (settingsBuilder == null) {
        settingsBuilder = Settings.settingsBuilder();
    }
    settingsBuilder.put(key, value);
}
 
Example 15
Source File: BaseClient.java    From elasticsearch-helper with Apache License 2.0 4 votes vote down vote up
public Settings.Builder settingsBuilder() {
    return settingsBuilder != null ? settingsBuilder : Settings.settingsBuilder();
}