org.elasticsearch.common.settings.loader.JsonSettingsLoader Java Examples
The following examples show how to use
org.elasticsearch.common.settings.loader.JsonSettingsLoader.
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: ConfigurationLoader.java From openshift-elasticsearch-plugin with Apache License 2.0 | 5 votes |
private Settings toSettings(final BytesReference ref, final String type) { if (ref == null || ref.length() == 0) { return null; } XContentParser parser = null; try { parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, ref, XContentType.JSON); parser.nextToken(); parser.nextToken(); if(!type.equals((parser.currentName()))) { return null; } parser.nextToken(); return Settings.builder().put(new JsonSettingsLoader(true).load(parser.binaryValue())).build(); } catch (final IOException e) { throw ExceptionsHelper.convertToElastic(e); } finally { if(parser != null) { parser.close(); } } }
Example #2
Source File: BaseElasticSearchIndexBuilder.java From sakai with Educational Community License v2.0 | 4 votes |
protected Map<String,String> initializeElasticSearchIndexSettings(String injectedConfig) { String defaultConfig = injectedConfig; if (org.apache.commons.lang3.StringUtils.isEmpty(injectedConfig)) { try { StringWriter writer = new StringWriter(); IOUtils.copy(getClass().getResourceAsStream(this.defaultIndexSettingsResource), writer, "UTF-8"); defaultConfig = writer.toString(); } catch (Exception ex) { getLog().error("Failed to load indexSettings config from ["+ this.defaultIndexSettingsResource + "] for index builder [" + getName() + "]", ex); } } JsonSettingsLoader loader = new JsonSettingsLoader(); Map<String, String> mergedConfig = null; try { mergedConfig = loader.load(defaultConfig); } catch (IOException e) { getLog().error("Problem loading indexSettings for index builder [" + getName() + "]", e); } // Set these here so we don't have to do this string concatenation // and comparison every time through the upcoming 'for' loop final boolean IS_DEFAULT = SearchIndexBuilder.DEFAULT_INDEX_BUILDER_NAME.equals(getName()); final String DEFAULT_INDEX = ElasticSearchConstants.CONFIG_PROPERTY_PREFIX + "index."; final String LOCAL_INDEX = String.format("%s%s%s.",ElasticSearchConstants.CONFIG_PROPERTY_PREFIX,"index_",getName(),"."); // load anything set into the ServerConfigurationService that starts with "elasticsearch.index." this will // override anything set in the indexSettings config for (ServerConfigurationService.ConfigItem configItem : serverConfigurationService.getConfigData().getItems()) { String propertyName = configItem.getName(); if (IS_DEFAULT && (propertyName.startsWith(DEFAULT_INDEX))) { propertyName = propertyName.replaceFirst(DEFAULT_INDEX, "index."); mergedConfig.put(propertyName, (String) configItem.getValue()); } else if (propertyName.startsWith(LOCAL_INDEX)) { propertyName = propertyName.replaceFirst(LOCAL_INDEX, "index."); mergedConfig.put(propertyName, (String) configItem.getValue()); } } if (getLog().isDebugEnabled()) { for (Map.Entry<String,String> entry : mergedConfig.entrySet()) { getLog().debug("Index property '" + entry.getKey() + "' set to: " + entry.getValue() + "' for index builder '" + getName() + "'"); } } return mergedConfig; }
Example #3
Source File: BaseElasticSearchIndexBuilder.java From sakai with Educational Community License v2.0 | 4 votes |
protected Map<String,String> initializeElasticSearchIndexSettings(String injectedConfig) { String defaultConfig = injectedConfig; if (org.apache.commons.lang3.StringUtils.isEmpty(injectedConfig)) { try { StringWriter writer = new StringWriter(); IOUtils.copy(getClass().getResourceAsStream(this.defaultIndexSettingsResource), writer, "UTF-8"); defaultConfig = writer.toString(); } catch (Exception ex) { getLog().error("Failed to load indexSettings config from ["+ this.defaultIndexSettingsResource + "] for index builder [" + getName() + "]", ex); } } JsonSettingsLoader loader = new JsonSettingsLoader(); Map<String, String> mergedConfig = null; try { mergedConfig = loader.load(defaultConfig); } catch (IOException e) { getLog().error("Problem loading indexSettings for index builder [" + getName() + "]", e); } // Set these here so we don't have to do this string concatenation // and comparison every time through the upcoming 'for' loop final boolean IS_DEFAULT = SearchIndexBuilder.DEFAULT_INDEX_BUILDER_NAME.equals(getName()); final String DEFAULT_INDEX = ElasticSearchConstants.CONFIG_PROPERTY_PREFIX + "index."; final String LOCAL_INDEX = String.format("%s%s%s.",ElasticSearchConstants.CONFIG_PROPERTY_PREFIX,"index_",getName(),"."); // load anything set into the ServerConfigurationService that starts with "elasticsearch.index." this will // override anything set in the indexSettings config for (ServerConfigurationService.ConfigItem configItem : serverConfigurationService.getConfigData().getItems()) { String propertyName = configItem.getName(); if (IS_DEFAULT && (propertyName.startsWith(DEFAULT_INDEX))) { propertyName = propertyName.replaceFirst(DEFAULT_INDEX, "index."); mergedConfig.put(propertyName, (String) configItem.getValue()); } else if (propertyName.startsWith(LOCAL_INDEX)) { propertyName = propertyName.replaceFirst(LOCAL_INDEX, "index."); mergedConfig.put(propertyName, (String) configItem.getValue()); } } if (getLog().isDebugEnabled()) { for (Map.Entry<String,String> entry : mergedConfig.entrySet()) { getLog().debug("Index property '" + entry.getKey() + "' set to: " + entry.getValue() + "' for index builder '" + getName() + "'"); } } return mergedConfig; }
Example #4
Source File: FulltextAnalyzerResolver.java From Elasticsearch with Apache License 2.0 | 2 votes |
public static Settings decodeSettings(String encodedSettings) throws IOException { Map<String, String> loaded = new JsonSettingsLoader().load(encodedSettings); return Settings.builder().put(loaded).build(); }