Reputation: 517
In elasticsearch 1.x, I used to call:
org.elasticsearch.bootstrap.Elasticsearch.main(args)
But in 5.x, they made the class org.elasticsearch.bootstrap.Elasticsearch package-private (default), so I am not able to run the ES server from java code in a neat way anymore. Is there any alternative neat way to do it (something different than Runtime exec or Apache Commons Exec)?
Thank you!
Upvotes: 1
Views: 515
Reputation: 517
Thanks everyone for reply. As they mentioned, it's not supported neither recommended. However, if you must, you can create a package in your application: org.elasticsearch.bootstrap
And then copy/paste in the package the Elasticsearch class from source: https://github.com/elastic/elasticsearch/blob/5.1/core/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java
Then from your application, you can call the main method and pass your arguments to it: ElasticsearchLauncher.main(args);
Upvotes: 0
Reputation: 14492
You can not. It's not supported.
See https://www.elastic.co/blog/elasticsearch-the-server
Embedded Elasticsearch not supported
Some users run Elasticsearch as embedded. We are not going to stop them from doing so, but we cannot support it. Embedding Elasticsearch bypasses the security manager, the Jar Hell checks, the bootstrap checks, and plugin loading. It is inherently unsafe and not recommended for production. For the sanity of our developers and support team, we cannot support users who disable all of the safety mechanisms which we have added for good reasons. For the same reason, we will not accept pull requests or make changes specifically to support the embedded use case
Upvotes: 1