I am trying to run a local Elasticsearch instance from within Java, but it's spamming my console with all sorts of messages. This is my code to build the settings and create the node:
Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", "localcluster")
//Paths
.put("path.data", "ESConsole/data")
.put("path.logs", "ESConsole/logs")
.put("path.work", "ESConsole/work")
.put("path.plugins", "ESConsole/plugins")
.put("path.conf", "ESConsole/config")
//Make the node unreachable from the outside
.put("discovery.zen.ping.multicast.enabled", false)
.put("node.local", true)
.put("http.enabled", false)
.build();
this.node = NodeBuilder.nodeBuilder().settings(settings).node();
I have tried creating a logger.yml and log4j.properties file and set the logging level to "ERROR" (as per this question), but that didn't seem to work (unless I did something really wrong). Is there a simple setting I can put in the settings builder (preferably) or do I have to create a settings file?
The reason I am asking this here is because all I could find was people that said something about a config file, while I would prefer to keep everything in code. If that's not possible, please let me know ;)
Thanks!
What I ended up doing is this:
Settings settings = settingsBuilder()
.put("http.enabled", false)
.put("network.host", "127.0.0.1")
.put("cluster.name", "my_cluster_name")
.put("node.name", "my_node_name")
.put("path.home", HOME.getAbsolutePath())
.put("path.conf", CONFIG.getAbsolutePath())
.put("path.logs", LOGS.getAbsolutePath())
.build();
// make sure ES' logging system knows where to find our custom logging.xml
LogConfigurator.configure(settings);
// startup a standalone node to use for tests
return nodeBuilder()
.settings(settings)
.local(true)
.loadConfigSettings(false)
.node();
The key here is the LogConfigurator.configure() call. Note that I did have to copy a custom logging.yml file into the path.logs directory that simply disables the console logger.
I suspect if the settings included logger.level = OFF, then you wouldn't need a custom logging.yml file at all, but then you'd have zero logging (which might be what you want).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With