首页 文章

从java启动Elastic Search而不是任何批处理文件

提问于
浏览
0

我对此完全陌生 . . . 我想用java代码开始弹性搜索,用main方法说

`Node node = nodeBuilder().local( true ).node();
        Client client = node.client();
        node.start();`

我使用上面的代码运行它运行没有错误,但它只停止两秒后我在控制台中看到的东西

log4j:WARN No appenders could be found for logger (org.elasticsearch.node).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

请帮助大家,这里是类似问题的链接,但它有助于帮助

starting elasticsearch instance from java?

1 回答

  • 0

    如果您的代码没有其他内容,则问题是它自己的ES线程不会使程序保持活动状态 . 你需要有一个自己的线程来保持它活着..例如:

    BasicConfigurator.configure();
        Node node = NodeBuilder.nodeBuilder().local(true).node();
        node.start();
        while (!node.isClosed()) {
            try {
                Thread.sleep(60*1000);
            } catch (InterruptedException e) {
                node.close();
            }
        }
        node.stop();
    

相关问题