0
votes

I ma totally new to this . . . I want to start Elastic search by java code say by a main method


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

I used the above code to run it which runs without error but it stops after two seconds only thing that i see in console is

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.

Kindly help guys and here is the link of a similar question but it dint helped

starting elasticsearch instance from java?

1
add BasicConfigurator.configure() to your code before instantiating the Client so that you can provide the error message that's causing issues.Alcanzar

1 Answers

0
votes

If there is nothing else to your code, the issue is that the ES thread on it's own won't keep the program alive. You need to have a thread of your own to keep it alive.. for example:

    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();