Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,28 @@ public TransportClient(Settings.Builder settings, boolean loadConfigSettings) th
* be loaded from the classpath / file system (the <tt>elasticsearch.(yml|json)</tt> files optionally prefixed with
* <tt>config/</tt>).
*
* @param pSettings The explicit settings.
* @param settings The explicit settings.
* @param loadConfigSettings <tt>true</tt> if settings should be loaded from the classpath/file system.
* @throws ElasticSearchException
*/
public TransportClient(Settings pSettings, boolean loadConfigSettings) throws ElasticSearchException {
Tuple<Settings, Environment> tuple = InternalSettingsPerparer.prepareSettings(pSettings, loadConfigSettings);
this(pSettings, loadConfigSettings, true);
}

/**
* Constructs a new transport client with the provided settings and the ability to control if settings will
* be loaded from the classpath / file system (the <tt>elasticsearch.(yml|json)</tt> files optionally prefixed with
* <tt>config/</tt>).
*
* Also, we allow the ability to control if settings will be loaded from the System Properties.
*
* @param pSettings The explicit settings.
* @param loadConfigSettings <tt>true</tt> if settings should be loaded from the classpath/file system.
* @param loadSystemProperties <tt>true</tt> if settings should be loaded from the System properties.
* @throws ElasticSearchException
*/
public TransportClient(Settings pSettings, boolean loadConfigSettings, boolean loadSystemProperties) throws ElasticSearchException {
Tuple<Settings, Environment> tuple = InternalSettingsPerparer.prepareSettings(pSettings, loadConfigSettings, loadSystemProperties);
Settings settings = settingsBuilder().put(tuple.v1())
.put("network.server", false)
.put("node.client", true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,24 @@
public class InternalSettingsPerparer {

public static Tuple<Settings, Environment> prepareSettings(Settings pSettings, boolean loadConfigSettings) {
return prepareSettings(pSettings, loadConfigSettings, true);
}

public static Tuple<Settings, Environment> prepareSettings(Settings pSettings, boolean loadConfigSettings, boolean loadSystemProperties) {
// ignore this prefixes when getting properties from es. and elasticsearch.
String[] ignorePrefixes = new String[]{"es.default.", "elasticsearch.default."};
// just create enough settings to build the environment
ImmutableSettings.Builder settingsBuilder = settingsBuilder()
.put(pSettings)
.putProperties("elasticsearch.default.", System.getProperties())
.put(pSettings);

if(loadSystemProperties){
settingsBuilder.putProperties("elasticsearch.default.", System.getProperties())
.putProperties("es.default.", System.getProperties())
.putProperties("elasticsearch.", System.getProperties(), ignorePrefixes)
.putProperties("es.", System.getProperties(), ignorePrefixes)
.replacePropertyPlaceholders();
.putProperties("es.", System.getProperties(), ignorePrefixes);
}

settingsBuilder.replacePropertyPlaceholders();

Environment environment = new Environment(settingsBuilder.build());

Expand Down Expand Up @@ -86,10 +94,12 @@ public static Tuple<Settings, Environment> prepareSettings(Settings pSettings, b
}
}

settingsBuilder.put(pSettings)
.putProperties("elasticsearch.", System.getProperties(), ignorePrefixes)
.putProperties("es.", System.getProperties(), ignorePrefixes)
.replacePropertyPlaceholders();
settingsBuilder.put(pSettings);
if(loadSystemProperties){
settingsBuilder.putProperties("elasticsearch.", System.getProperties(), ignorePrefixes)
.putProperties("es.", System.getProperties(), ignorePrefixes);
}
settingsBuilder.replacePropertyPlaceholders();

// generate the name
if (settingsBuilder.get("name") == null) {
Expand Down